diff --git a/README.md b/README.md index 3c41826..99bb117 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ # gitlab-api-ci-finder (glcifinder) +## How to run +`python glcifinder-cli.py --count 1000 --projectid 244 --jobname deploy-test` + diff --git a/gitlab_api_finder.py b/gitlab_api_finder.py index e091575..804a7b7 100644 --- a/gitlab_api_finder.py +++ b/gitlab_api_finder.py @@ -44,6 +44,17 @@ def calc_number_of_pages_number(total_number): return MAX_NUMBER_OF_ITEMS_PER_PAGE, round(total_number / MAX_NUMBER_OF_ITEMS_PER_PAGE) +def filter_relevant_attributes(job): + relevant_job = { + 'status': job['status'], + 'name': job['name'], + 'ref': job['ref'], + 'started_at': job['started_at'], + 'commit_id': job['commit']['id'] + } + return relevant_job + + def find_jobs(count, project_id, job_name): number_of_items_per_page, number_of_pages = calc_number_of_pages_number(count) # NUMBER_OF_ITEMS_PER_PAGE = 100 @@ -69,5 +80,6 @@ def find_jobs(count, project_id, job_name): import itertools flat_list_of_jobs = list(itertools.chain(*response_array)) - find_jobs_by_name_that_were_run(flat_list_of_jobs, job_name) - # TODO filter output for relevant fields + list_of_successfull_jobs = find_jobs_by_name_that_were_run(flat_list_of_jobs, job_name) + # filter output for relevant fields + return list(map(filter_relevant_attributes, list_of_successfull_jobs)) diff --git a/glcifinder-cli.py b/glcifinder-cli.py index 5862722..2b860a5 100644 --- a/glcifinder-cli.py +++ b/glcifinder-cli.py @@ -7,6 +7,7 @@ import gitlab_api_finder @click.option("--count", default=1, help="Number of jobs to search.") @click.option("--projectid", prompt="Id of Gitlab Project", help="Id of Gitlab Project.") @click.option("--jobname", prompt="name of job to filter", help="Id of Gitlab Project.") +# TODO add option "to-file" for storing the resulting json on disk def hello(count, projectid, jobname): gitlab_api_finder.find_jobs(count, projectid, jobname) diff --git a/test_glcifinder.py b/test_glcifinder.py new file mode 100644 index 0000000..f6b54a9 --- /dev/null +++ b/test_glcifinder.py @@ -0,0 +1,10 @@ +import gitlab_api_finder + + +def test(): + count = 20 + projectid = 244 + jobname = "prepare" + result = gitlab_api_finder.find_jobs(count, projectid, jobname) + one_job = result[0] + assert one_job['status'] == 'success'