-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Allow to skip a build on commit messages #3457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f6d9780
e851bf0
e21af7e
634a6ed
3eea78b
177f0f7
f20fcd3
8150793
1c89e6a
64e00b0
435726c
24dd729
a930dc3
517d3eb
8ab67be
12147c8
b808ce4
c8b8756
836c9ca
806789d
97235a3
5803557
ce0fa0f
808f835
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,8 +137,16 @@ class GitHubWebhookView(WebhookMixin, APIView): | |
|
||
{ | ||
"ref": "branch-name", | ||
"head_commit": { | ||
"id": "sha", | ||
"message": "Update README.md", | ||
... | ||
} | ||
... | ||
} | ||
|
||
See full payload here: | ||
https://developer.github.com/v3/activity/events/types/#pushevent | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we using the v3 of the gh api? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems, https://developer.github.com/v3/#current-version, since we are not sending the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And also v4 is using GraphQL, this will break everything. |
||
""" | ||
|
||
integration_type = Integration.GITHUB_WEBHOOK | ||
|
@@ -159,7 +167,12 @@ def handle_webhook(self): | |
# Handle push events and trigger builds | ||
if event == GITHUB_PUSH: | ||
try: | ||
branches = [self.data['ref'].replace('refs/heads/', '')] | ||
# GitHub only returns one branch. | ||
branch = { | ||
'name': self.data['ref'].replace('refs/heads/', ''), | ||
'last_commit': self.data['head_commit'], | ||
} | ||
branches = [branch] | ||
return self.get_response_push(self.project, branches) | ||
except KeyError: | ||
raise ParseError('Parameter "ref" is required') | ||
|
@@ -177,8 +190,16 @@ class GitLabWebhookView(WebhookMixin, APIView): | |
{ | ||
"object_kind": "push", | ||
"ref": "branch-name", | ||
"commits": [{ | ||
"id": "sha", | ||
"message": "Update README.md", | ||
... | ||
}] | ||
... | ||
} | ||
|
||
See full payload here: | ||
https://docs.gitlab.com/ce/user/project/integrations/webhooks.html#push-events | ||
""" | ||
|
||
integration_type = Integration.GITLAB_WEBHOOK | ||
|
@@ -191,7 +212,13 @@ def handle_webhook(self): | |
# Handle push events and trigger builds | ||
if event == GITLAB_PUSH: | ||
try: | ||
branches = [self.request.data['ref'].replace('refs/heads/', '')] | ||
# GitLab only returns one branch. | ||
branch = { | ||
'name': self.request.data['ref'].replace('refs/heads/', ''), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Won't this interferes with your other PR at #3546? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just when merging/rebasing, on the logic everything would work as expected :) |
||
# Assuming the first element is the last commit. | ||
'last_commit': self.request.data['commits'][0], | ||
} | ||
branches = [branch] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another thought here... If we already know at this point the last commit message, shouldn't skip here the call to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need the (buid, not_building) from the |
||
return self.get_response_push(self.project, branches) | ||
except KeyError: | ||
raise ParseError('Parameter "ref" is required') | ||
|
@@ -211,6 +238,11 @@ class BitbucketWebhookView(WebhookMixin, APIView): | |
"changes": [{ | ||
"new": { | ||
"name": "branch-name", | ||
"target": { | ||
"hash": "sha", | ||
"message": "Update README.md", | ||
... | ||
} | ||
... | ||
}, | ||
... | ||
|
@@ -219,6 +251,9 @@ class BitbucketWebhookView(WebhookMixin, APIView): | |
}, | ||
... | ||
} | ||
|
||
See full payload here: | ||
https://confluence.atlassian.com/bitbucket/event-payloads-740262817.html#EventPayloads-Push | ||
""" | ||
|
||
integration_type = Integration.BITBUCKET_WEBHOOK | ||
|
@@ -232,13 +267,34 @@ def handle_webhook(self): | |
if event == BITBUCKET_PUSH: | ||
try: | ||
changes = self.request.data['push']['changes'] | ||
branches = [change['new']['name'] | ||
for change in changes | ||
if change.get('new')] | ||
branches = [ | ||
{ | ||
'name': change['new']['name'], | ||
'last_commit': self._normalize_commit( | ||
change['new']['target'] | ||
), | ||
} | ||
for change in changes | ||
if change.get('new') | ||
] | ||
return self.get_response_push(self.project, branches) | ||
except KeyError: | ||
raise ParseError('Invalid request') | ||
|
||
def _normalize_commit(self, commit): | ||
""" | ||
All commit dicts must have this elements at least:: | ||
|
||
{ | ||
'id': 'sha', | ||
'message': 'Update README.md', | ||
} | ||
""" | ||
return { | ||
'id': commit['hash'], | ||
'message': commit['message'], | ||
} | ||
|
||
|
||
class IsAuthenticatedOrHasToken(permissions.IsAuthenticated): | ||
|
||
|
@@ -265,6 +321,19 @@ class APIWebhookView(WebhookMixin, APIView): | |
{ | ||
"branches": ["master"] | ||
} | ||
|
||
Or the following JSON:: | ||
|
||
{ | ||
"branches": [{ | ||
"name": "branch-name", | ||
"last_commit": { | ||
"id": "sha", | ||
"message": "Update README.md" | ||
} | ||
}] | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is what I proposed for the general webhook, maintaining the backwards compatibility. |
||
""" | ||
|
||
integration_type = Integration.API_WEBHOOK | ||
|
@@ -300,12 +369,20 @@ def get_project(self, **kwargs): | |
|
||
def handle_webhook(self): | ||
try: | ||
branches = self.request.data.get( | ||
request_branches = self.request.data.get( | ||
'branches', | ||
[self.project.get_default_branch()] | ||
) | ||
if isinstance(branches, six.string_types): | ||
branches = [branches] | ||
if isinstance(request_branches, six.string_types): | ||
request_branches = [request_branches] | ||
branches = [] | ||
for branch in request_branches: | ||
if isinstance(branch, six.string_types): | ||
branches.append({ | ||
'name': branch, | ||
}) | ||
else: | ||
branches.append(branch) | ||
return self.get_response_push(self.project, branches) | ||
except TypeError: | ||
raise ParseError('Invalid request') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the logic for skipping the build, not sure if this is the correct place
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, if the last commit contains the mark we don't build any version?
I'm confused here since the next few lines there is a logic that can build some version but not some others comming in the same webhook, right? Shouldn't we apply a similar logic here also?
That
to_build
andnot_building
rely on the function_build_version
. So, this logic shouldn't be in that method? (I don't know, but is has the logging integrated and returns what it needs. On the other hand, it seems that we shouldn't call that method if we already know that we need to skip the version but there are some logic to skip versions inside that function too :/There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of what I understand, a branch/tag/commit can be tied to various versions so there is only one commit message for all versions, this means that all versions from this branch aren't going to be built. And also is about what you mention, we already know if the version isn't going to be built.