add method to filter relevant fields, unit test
This commit is contained in:
parent
b74fd6695f
commit
25564357bb
@ -1,3 +1,6 @@
|
|||||||
# gitlab-api-ci-finder (glcifinder)
|
# gitlab-api-ci-finder (glcifinder)
|
||||||
|
|
||||||
|
|
||||||
|
## How to run
|
||||||
|
`python glcifinder-cli.py --count 1000 --projectid 244 --jobname deploy-test`
|
||||||
|
|
||||||
|
@ -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)
|
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):
|
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, number_of_pages = calc_number_of_pages_number(count)
|
||||||
# NUMBER_OF_ITEMS_PER_PAGE = 100
|
# NUMBER_OF_ITEMS_PER_PAGE = 100
|
||||||
@ -69,5 +80,6 @@ def find_jobs(count, project_id, job_name):
|
|||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
flat_list_of_jobs = list(itertools.chain(*response_array))
|
flat_list_of_jobs = list(itertools.chain(*response_array))
|
||||||
find_jobs_by_name_that_were_run(flat_list_of_jobs, job_name)
|
list_of_successfull_jobs = find_jobs_by_name_that_were_run(flat_list_of_jobs, job_name)
|
||||||
# TODO filter output for relevant fields
|
# filter output for relevant fields
|
||||||
|
return list(map(filter_relevant_attributes, list_of_successfull_jobs))
|
||||||
|
@ -7,6 +7,7 @@ import gitlab_api_finder
|
|||||||
@click.option("--count", default=1, help="Number of jobs to search.")
|
@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("--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.")
|
@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):
|
def hello(count, projectid, jobname):
|
||||||
gitlab_api_finder.find_jobs(count, projectid, jobname)
|
gitlab_api_finder.find_jobs(count, projectid, jobname)
|
||||||
|
|
||||||
|
10
test_glcifinder.py
Normal file
10
test_glcifinder.py
Normal file
@ -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'
|
Loading…
x
Reference in New Issue
Block a user