Skip to content
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

Use actual Merge Request number for GitLab MRs #3060

Merged
merged 1 commit into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions services/webhooks2tasks/src/handlers/gitlabPullRequestClosed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function gitlabPullRequestClosed(webhook: WebhookRequestData, proje

const meta: { [key: string]: any } = {
projectName: project.name,
pullrequestNumber: body.object_attributes.id,
pullrequestNumber: body.object_attributes.iid,
pullrequestTitle: body.object_attributes.title,
pullrequestUrl: body.object_attributes.url,
repoName: body.object_attributes.target.name,
Expand All @@ -29,7 +29,7 @@ export async function gitlabPullRequestClosed(webhook: WebhookRequestData, proje
const ocsafety = string =>
string.toLocaleLowerCase().replace(/[^0-9a-z-]/g, '-');

let branchName = `pr-${body.object_attributes.id}`
let branchName = `pr-${body.object_attributes.iid}`
let openshiftProjectName = projectOpenShift.openshiftProjectPattern
? projectOpenShift.openshiftProjectPattern
.replace('${branch}', ocsafety(branchName))
Expand All @@ -38,7 +38,7 @@ export async function gitlabPullRequestClosed(webhook: WebhookRequestData, proje

const data: removeData = {
projectName: project.name,
pullrequestNumber: body.object_attributes.id,
pullrequestNumber: body.object_attributes.iid,
pullrequestTitle: body.object_attributes.title,
branch: branchName,
openshiftProjectName: openshiftProjectName,
Expand All @@ -48,7 +48,7 @@ export async function gitlabPullRequestClosed(webhook: WebhookRequestData, proje
try {
await createRemoveTask(data);
sendToLagoonLogs('info', project.name, uuid, `${webhooktype}:${event}:closed:handled`, meta,
`*[${project.name}]* PR <${body.object_attributes.url}|#${body.object_attributes.id} (${body.object_attributes.title})> closed in <${body.object_attributes.target.web_url}|${body.object_attributes.target.name}>`
`*[${project.name}]* PR <${body.object_attributes.url}|#${body.object_attributes.iid} (${body.object_attributes.title})> closed in <${body.object_attributes.target.web_url}|${body.object_attributes.target.name}>`
)
return;
} catch (error) {
Expand All @@ -58,7 +58,7 @@ export async function gitlabPullRequestClosed(webhook: WebhookRequestData, proje
case "UnknownActiveSystem":
// These are not real errors and also they will happen many times. We just log them locally but not throw an error
sendToLagoonLogs('info', project.name, uuid, `${webhooktype}:${event}:handledButNoTask`, meta,
`*[${project.name}]* PR ${body.object_attributes.id} closed. No remove task created, reason: ${error}`
`*[${project.name}]* PR ${body.object_attributes.iid} closed. No remove task created, reason: ${error}`
)
return;

Expand Down
10 changes: 5 additions & 5 deletions services/webhooks2tasks/src/handlers/gitlabPullRequestOpened.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function gitlabPullRequestOpened(webhook: WebhookRequestData, proje

const meta = {
projectName: project.name,
pullrequestNumber: body.object_attributes.id,
pullrequestNumber: body.object_attributes.iid,
pullrequestTitle: body.object_attributes.title,
pullrequestUrl: body.object_attributes.url,
repoName: body.object_attributes.target.name,
Expand Down Expand Up @@ -46,21 +46,21 @@ export async function gitlabPullRequestOpened(webhook: WebhookRequestData, proje
repoName: body.object_attributes.target.name,
pullrequestUrl: body.object_attributes.url,
pullrequestTitle: body.object_attributes.title,
pullrequestNumber: body.object_attributes.id,
pullrequestNumber: body.object_attributes.iid,
projectName: project.name,
type: 'pullrequest',
headBranchName: headBranchName,
headSha: headSha,
baseBranchName: baseBranchName,
baseSha: baseSha,
branchName: `pr-${body.object_attributes.id}`,
branchName: `pr-${body.object_attributes.iid}`,
buildName: buildName
}

try {
await createDeployTask(data);
sendToLagoonLogs('info', project.name, uuid, `${webhooktype}:${event}:opened:handled`, data,
`*[${project.name}]* PR <${body.object_attributes.url}|#${body.object_attributes.id} (${body.object_attributes.title})> opened in <${body.object_attributes.target.web_url}|${body.object_attributes.target.name}>`
`*[${project.name}]* PR <${body.object_attributes.url}|#${body.object_attributes.iid} (${body.object_attributes.title})> opened in <${body.object_attributes.target.web_url}|${body.object_attributes.target.name}>`
)
return;
} catch (error) {
Expand All @@ -70,7 +70,7 @@ export async function gitlabPullRequestOpened(webhook: WebhookRequestData, proje
case "UnknownActiveSystem":
// These are not real errors and also they will happen many times. We just log them locally but not throw an error
sendToLagoonLogs('info', project.name, uuid, `${webhooktype}:${event}:handledButNoTask`, meta,
`*[${project.name}]* PR ${body.object_attributes.id} opened. No deploy task created, reason: ${error}`
`*[${project.name}]* PR ${body.object_attributes.iid} opened. No deploy task created, reason: ${error}`
)
return;

Expand Down
10 changes: 5 additions & 5 deletions services/webhooks2tasks/src/handlers/gitlabPullRequestUpdated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function gitlabPullRequestUpdated(webhook: WebhookRequestData, proj

const meta = {
projectName: project.name,
pullrequestNumber: body.object_attributes.id,
pullrequestNumber: body.object_attributes.iid,
pullrequestTitle: body.object_attributes.title,
pullrequestUrl: body.object_attributes.url,
repoName: body.object_attributes.target.name,
Expand Down Expand Up @@ -46,22 +46,22 @@ export async function gitlabPullRequestUpdated(webhook: WebhookRequestData, proj
repoName: body.object_attributes.target.name,
pullrequestUrl: body.object_attributes.url,
pullrequestTitle: body.object_attributes.title,
pullrequestNumber: body.object_attributes.id,
pullrequestNumber: body.object_attributes.iid,
projectName: project.name,
type: 'pullrequest',
headBranchName: headBranchName,
headSha: headSha,
baseBranchName: baseBranchName,
baseSha: baseSha,
branchName: `pr-${body.object_attributes.id}`,
branchName: `pr-${body.object_attributes.iid}`,
buildName: buildName
}

try {
await createDeployTask(data);
// gitlab does not identify well that this is an update to a merge request, so we manually set the event type here.
sendToLagoonLogs('info', project.name, uuid, `${webhooktype}:${event}:updated:handled`, data,
`*[${project.name}]* PR <${body.object_attributes.url}|#${body.object_attributes.id} (${body.object_attributes.title})> updated in <${body.object_attributes.target.web_url}|${body.object_attributes.target.name}>`
`*[${project.name}]* PR <${body.object_attributes.url}|#${body.object_attributes.iid} (${body.object_attributes.title})> updated in <${body.object_attributes.target.web_url}|${body.object_attributes.target.name}>`
)
return;
} catch (error) {
Expand All @@ -71,7 +71,7 @@ export async function gitlabPullRequestUpdated(webhook: WebhookRequestData, proj
case "UnknownActiveSystem":
// These are not real errors and also they will happen many times. We just log them locally but not throw an error
sendToLagoonLogs('info', project.name, uuid, `${webhooktype}:${event}:handledButNoTask`, meta,
`*[${project.name}]* PR ${body.object_attributes.id} updated. No deploy task created, reason: ${error}`
`*[${project.name}]* PR ${body.object_attributes.iid} updated. No deploy task created, reason: ${error}`
)
return;

Expand Down
2 changes: 1 addition & 1 deletion tests/tasks/webhook-gitlab/pullrequest-closed.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
method: POST
follow_redirects: yes
body_format: json
body: '{"object_kind":"merge_request","user":{"name":"Michael Schmid","username":"michael.schmid1","avatar_url":"https://secure.gravatar.com/avatar/c4f5bd5f32eec798c2df7afe0040c49f?s=80\u0026d=identicon"},"project":{"id":"1","name":"test","description":"","web_url":"https://gitlab.com/michael.schmid1/test","avatar_url":null,"git_ssh_url":"{{ git_repo_ssh_url }}","git_http_url":"https://gitlab.com/michael.schmid1/test.git","namespace":"michael.schmid1","visibility_level":0,"path_with_namespace":"michael.schmid1/test","default_branch":"master","ci_config_path":null,"homepage":"https://gitlab.com/michael.schmid1/test","url":"git@gitlab.com:michael.schmid1/test.git","ssh_url":"git@gitlab.com:michael.schmid1/test.git","http_url":"https://gitlab.com/michael.schmid1/test.git"},"object_attributes":{"assignee_id":null,"author_id":2127130,"created_at":"2018-03-19 00:01:08 UTC","description":"bla bla bbla","head_pipeline_id":null,"id":"{{ git_pr_number }}","iid":1,"last_edited_at":"2018-03-19 00:04:33 UTC","last_edited_by_id":2127130,"merge_commit_sha":null,"merge_error":null,"merge_params":{"force_remove_source_branch":"0"},"merge_status":"unchecked","merge_user_id":null,"merge_when_pipeline_succeeds":false,"milestone_id":null,"source_branch":"{{ git_pr_branch }}","source_project_id":5796982,"state":"merged","target_branch":"{{ git_base_branch }}","target_project_id":5796982,"time_estimate":0,"title":"My Merge Request edit","updated_at":"2018-03-19 00:07:53 UTC","updated_by_id":2127130,"url":"https://gitlab.com/michael.schmid1/test/merge_requests/1","source":{"id":5796982,"name":"test","description":"","web_url":"https://gitlab.com/michael.schmid1/test","avatar_url":null,"git_ssh_url":"git@gitlab.com:michael.schmid1/test.git","git_http_url":"https://gitlab.com/michael.schmid1/test.git","namespace":"michael.schmid1","visibility_level":0,"path_with_namespace":"michael.schmid1/test","default_branch":"master","ci_config_path":null,"homepage":"https://gitlab.com/michael.schmid1/test","url":"git@gitlab.com:michael.schmid1/test.git","ssh_url":"git@gitlab.com:michael.schmid1/test.git","http_url":"https://gitlab.com/michael.schmid1/test.git"},"target":{"id":5796982,"name":"test","description":"","web_url":"https://gitlab.com/michael.schmid1/test","avatar_url":null,"git_ssh_url":"git@gitlab.com:michael.schmid1/test.git","git_http_url":"https://gitlab.com/michael.schmid1/test.git","namespace":"michael.schmid1","visibility_level":0,"path_with_namespace":"michael.schmid1/test","default_branch":"master","ci_config_path":null,"homepage":"https://gitlab.com/michael.schmid1/test","url":"git@gitlab.com:michael.schmid1/test.git","ssh_url":"git@gitlab.com:michael.schmid1/test.git","http_url":"https://gitlab.com/michael.schmid1/test.git"},"last_commit":{"id":"{{ git_pr_commit_hash }}","message":"edit test2","timestamp":"2018-03-19T00:06:27+00:00","url":"https://gitlab.com/michael.schmid1/test/commit/3f116b9ce232c1c84ddac414abb73e985b67aee2","author":{"name":"Michael Schmid","email":"michael.schmid@amazee.com"}},"work_in_progress":false,"total_time_spent":0,"human_total_time_spent":null,"human_time_estimate":null,"action":"merge"},"labels":[],"changes":{"state":{"previous":"opened","current":"closed"},"updated_at":{"previous":"2018-03-19 00:06:28 UTC","current":"2018-03-19 00:07:53 UTC"},"total_time_spent":{"previous":null,"current":0}},"repository":{"name":"test","url":"git@gitlab.com:michael.schmid1/test.git","description":"","homepage":"https://gitlab.com/michael.schmid1/test"}}'
body: '{"object_kind":"merge_request","user":{"name":"Michael Schmid","username":"michael.schmid1","avatar_url":"https://secure.gravatar.com/avatar/c4f5bd5f32eec798c2df7afe0040c49f?s=80\u0026d=identicon"},"project":{"id":"1","name":"test","description":"","web_url":"https://gitlab.com/michael.schmid1/test","avatar_url":null,"git_ssh_url":"{{ git_repo_ssh_url }}","git_http_url":"https://gitlab.com/michael.schmid1/test.git","namespace":"michael.schmid1","visibility_level":0,"path_with_namespace":"michael.schmid1/test","default_branch":"master","ci_config_path":null,"homepage":"https://gitlab.com/michael.schmid1/test","url":"git@gitlab.com:michael.schmid1/test.git","ssh_url":"git@gitlab.com:michael.schmid1/test.git","http_url":"https://gitlab.com/michael.schmid1/test.git"},"object_attributes":{"assignee_id":null,"author_id":2127130,"created_at":"2018-03-19 00:01:08 UTC","description":"bla bla bbla","head_pipeline_id":null,"id":123456789,"iid":"{{ git_pr_number }}","last_edited_at":"2018-03-19 00:04:33 UTC","last_edited_by_id":2127130,"merge_commit_sha":null,"merge_error":null,"merge_params":{"force_remove_source_branch":"0"},"merge_status":"unchecked","merge_user_id":null,"merge_when_pipeline_succeeds":false,"milestone_id":null,"source_branch":"{{ git_pr_branch }}","source_project_id":5796982,"state":"merged","target_branch":"{{ git_base_branch }}","target_project_id":5796982,"time_estimate":0,"title":"My Merge Request edit","updated_at":"2018-03-19 00:07:53 UTC","updated_by_id":2127130,"url":"https://gitlab.com/michael.schmid1/test/merge_requests/1","source":{"id":5796982,"name":"test","description":"","web_url":"https://gitlab.com/michael.schmid1/test","avatar_url":null,"git_ssh_url":"git@gitlab.com:michael.schmid1/test.git","git_http_url":"https://gitlab.com/michael.schmid1/test.git","namespace":"michael.schmid1","visibility_level":0,"path_with_namespace":"michael.schmid1/test","default_branch":"master","ci_config_path":null,"homepage":"https://gitlab.com/michael.schmid1/test","url":"git@gitlab.com:michael.schmid1/test.git","ssh_url":"git@gitlab.com:michael.schmid1/test.git","http_url":"https://gitlab.com/michael.schmid1/test.git"},"target":{"id":5796982,"name":"test","description":"","web_url":"https://gitlab.com/michael.schmid1/test","avatar_url":null,"git_ssh_url":"git@gitlab.com:michael.schmid1/test.git","git_http_url":"https://gitlab.com/michael.schmid1/test.git","namespace":"michael.schmid1","visibility_level":0,"path_with_namespace":"michael.schmid1/test","default_branch":"master","ci_config_path":null,"homepage":"https://gitlab.com/michael.schmid1/test","url":"git@gitlab.com:michael.schmid1/test.git","ssh_url":"git@gitlab.com:michael.schmid1/test.git","http_url":"https://gitlab.com/michael.schmid1/test.git"},"last_commit":{"id":"{{ git_pr_commit_hash }}","message":"edit test2","timestamp":"2018-03-19T00:06:27+00:00","url":"https://gitlab.com/michael.schmid1/test/commit/3f116b9ce232c1c84ddac414abb73e985b67aee2","author":{"name":"Michael Schmid","email":"michael.schmid@amazee.com"}},"work_in_progress":false,"total_time_spent":0,"human_total_time_spent":null,"human_time_estimate":null,"action":"merge"},"labels":[],"changes":{"state":{"previous":"opened","current":"closed"},"updated_at":{"previous":"2018-03-19 00:06:28 UTC","current":"2018-03-19 00:07:53 UTC"},"total_time_spent":{"previous":null,"current":0}},"repository":{"name":"test","url":"git@gitlab.com:michael.schmid1/test.git","description":"","homepage":"https://gitlab.com/michael.schmid1/test"}}'
Loading