Skip to content

Commit

Permalink
No job_regexp by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Jellby committed Dec 5, 2019
1 parent d7408d2 commit b61c604
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 23 deletions.
2 changes: 1 addition & 1 deletion marge/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def regexp(str_regex):
parser.add_argument(
'--job-regexp',
type=regexp,
default='.*',
default='',
help='Require pipelines to have jobs matching the given regular expression.\n',
)
parser.add_argument(
Expand Down
2 changes: 1 addition & 1 deletion marge/batch_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def accept_mr(

sleep(2)

# At this point Gitlab should have recognised the MR as being accepted.
# At this point GitLab should have recognised the MR as being accepted.
log.info('Successfully merged MR !%s', merge_request.iid)

pipelines = Pipeline.pipelines_by_branch(
Expand Down
19 changes: 10 additions & 9 deletions marge/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,15 @@ def get_mr_ci_status(self, merge_request, commit_sha=None):

if current_pipeline:
ci_status = current_pipeline.status
jobs = current_pipeline.get_jobs()
if not any(self.opts.job_regexp.match(j['name']) for j in jobs):
if create_pipeline:
message = 'CI doesn\'t contain the required jobs.'
log.warning(message)
trigger = True
else:
raise CannotMerge('CI doesn\'t contain the required jobs.')
if self.opts.job_regexp.pattern:
jobs = current_pipeline.get_jobs()
if not any(self.opts.job_regexp.match(j['name']) for j in jobs):
if create_pipeline:
message = 'CI doesn\'t contain the required jobs.'
log.warning(message)
trigger = True
else:
raise CannotMerge('CI doesn\'t contain the required jobs.')
else:
message = 'No pipeline listed for {sha} on branch {branch}.'.format(
sha=commit_sha, branch=merge_request.source_branch
Expand Down Expand Up @@ -472,7 +473,7 @@ def default(
cls, *,
add_tested=False, add_part_of=False, add_reviewers=False, reapprove=False,
approval_timeout=None, embargo=None, ci_timeout=None, fusion=Fusion.rebase,
job_regexp=re.compile('.*'), create_pipeline=False
job_regexp=re.compile(''), create_pipeline=False
):
approval_timeout = approval_timeout or timedelta(seconds=0)
embargo = embargo or IntervalUnion.empty()
Expand Down
1 change: 1 addition & 0 deletions marge/merge_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
GET, POST, PUT, DELETE = gitlab.GET, gitlab.POST, gitlab.PUT, gitlab.DELETE


# pylint: disable=R0904
class MergeRequest(gitlab.Resource):

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion marge/single_merge_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def update_merge_request_and_accept(self, approvals):
source_repo_url=source_repo_url,
)
except GitLabRebaseResultMismatch:
log.info("Gitlab rebase didn't give expected result")
log.info("GitLab rebase didn't give expected result")
merge_request.comment("Someone skipped the queue! Will have to try again...")
continue

Expand Down
9 changes: 2 additions & 7 deletions tests/gitlab_api_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,8 @@ def add_transition(self, command, response, sudo=None, from_state=None, to_state
)
self._transitions[_key(command, sudo, _from_state)] = (response, to_state, side_effect)

def add_resource(self, path, info, sudo=None, from_state=None, to_state=None, result=None):
if result is None:
self.add_transition(GET(path.format(attrs(info))), Ok(info), sudo, from_state, to_state)
else:
self.add_transition(GET(path.format(attrs(info))), Ok(result), sudo, from_state, to_state)
def add_resource(self, path, info, sudo=None, from_state=None, to_state=None):
self.add_transition(GET(path.format(attrs(info))), Ok(info), sudo, from_state, to_state)

def add_user(self, info, is_current=False, sudo=None, from_state=None, to_state=None):
self.add_resource('/users/{0.id}', info, sudo, from_state, to_state)
Expand Down Expand Up @@ -193,8 +190,6 @@ def add_pipelines(self, project_id, info, sudo=None, from_state=None, to_state=N
Ok([info]),
sudo, from_state, to_state,
)
path = '/projects/%s/pipelines/{0.id}/jobs' % project_id
self.add_resource(path, info, sudo, None, None, result=info['jobs'])

def expected_note(self, merge_request, note, sudo=None, from_state=None, to_state=None):
self.add_transition(
Expand Down
3 changes: 1 addition & 2 deletions tests/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def test_get_mr_ci_status(self, version, use_merge_request_pipelines):
]
pipeline_class.pipelines_by_branch.return_value = pipeline_success
pipeline_class.pipelines_by_merge_request.return_value = pipeline_success
pipeline_success[0].get_jobs.return_value = [{'name': 'job1'}]
merge_job = self.get_merge_job()
merge_job._api.version.return_value = marge.gitlab.Version.parse(version)
merge_request = self._mock_merge_request(sha='abc')
Expand Down Expand Up @@ -202,7 +201,7 @@ def test_default(self):
embargo=marge.interval.IntervalUnion.empty(),
ci_timeout=timedelta(minutes=15),
fusion=Fusion.rebase,
job_regexp=re.compile('.*'),
job_regexp=re.compile(''),
create_pipeline=False,
)

Expand Down
3 changes: 1 addition & 2 deletions tests/test_single_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def _pipeline(sha1, status, ref='useless_new_feature'):
'status': status,
'ref': ref,
'sha': sha1,
'jobs': [{'name': 'job1'}, {'name': 'job2'}],
}


Expand Down Expand Up @@ -647,7 +646,7 @@ def test_assumes_unresolved_discussions_on_merge_refusal(self, mocks):
from_state='unresolved_discussions',
)
message = (
"Gitlab refused to merge this request and I don't know why! "
"GitLab refused to merge this request and I don't know why! "
"Maybe you have unresolved discussions?"
)
with mocklab.expected_failure(message):
Expand Down

0 comments on commit b61c604

Please sign in to comment.