-
Notifications
You must be signed in to change notification settings - Fork 0
PLENG-339/unified trigger labels #10
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
base: main-ud
Are you sure you want to change the base?
Changes from all commits
c6686a1
081081f
8746c61
15f73ae
c932814
187e887
2dd5625
d354d2e
17f4705
7a394e8
ab3b360
0120a8b
f14af72
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 |
|---|---|---|
|
|
@@ -19,7 +19,13 @@ import _ from 'lodash'; | |
| import Service from './_service'; | ||
| import rootLogger from 'server/lib/logger'; | ||
| import { IssueCommentEvent, PullRequestEvent, PushEvent } from '@octokit/webhooks-types'; | ||
| import { GithubPullRequestActions, GithubWebhookTypes, PullRequestStatus, Labels } from 'shared/constants'; | ||
| import { | ||
| GithubPullRequestActions, | ||
| GithubWebhookTypes, | ||
| PullRequestStatus, | ||
| Labels, | ||
| PrTriggerLabels, | ||
| } from 'shared/constants'; | ||
| import { JOB_VERSION } from 'shared/config'; | ||
| import { NextApiRequest } from 'next'; | ||
| import * as github from 'server/lib/github'; | ||
|
|
@@ -140,14 +146,30 @@ export default class GithubService extends Service { | |
| lifecycleConfig, | ||
| }); | ||
|
|
||
| // if auto deploy, add deploy label` | ||
| if (isDeploy) | ||
| // if auto deploy, add deploy label | ||
| if (isDeploy) { | ||
| const currentLabels = labels.map((l) => l.name); | ||
| const hasDeployLabel = currentLabels.some((label) => | ||
| Array.isArray(PrTriggerLabels.DEPLOY) | ||
| ? PrTriggerLabels.DEPLOY.includes(label) | ||
| : label === PrTriggerLabels.DEPLOY | ||
| ); | ||
| const updatedLabels = hasDeployLabel | ||
| ? currentLabels | ||
| : [ | ||
| ...new Set([ | ||
| ...currentLabels, | ||
| ...(Array.isArray(PrTriggerLabels.DEPLOY) ? PrTriggerLabels.DEPLOY : [PrTriggerLabels.DEPLOY]), | ||
|
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 seems like it would add all the deploy labels to the PR. Do we want to it to just add the first deploy label instead?
Author
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. does it matter? like just adding the first label makes it cleaner or something? 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. I don't know how much it matters, but the reasons I can think of are:
Author
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. you only need to remove the initial label used |
||
| ]), | ||
| ]; | ||
|
|
||
| await github.updatePullRequestLabels({ | ||
| installationId, | ||
| pullRequestNumber: number, | ||
| fullName, | ||
| labels: labels.map((l) => l.name).concat(['lifecycle-deploy!']), | ||
| labels: updatedLabels, | ||
| }); | ||
| } | ||
| } else if (isClosed) { | ||
| build = await this.db.models.Build.findOne({ | ||
| pullRequestId, | ||
|
|
@@ -157,12 +179,18 @@ export default class GithubService extends Service { | |
| return; | ||
| } | ||
| await this.db.services.BuildService.deleteBuild(build); | ||
| // remove lifecycle-deploy! label on PR close | ||
| // remove the PrTriggerLabels.DEPLOY label(s) on PR close | ||
| const currentLabels = labels.map((l) => l.name); | ||
| const deployLabelsToRemove = Array.isArray(PrTriggerLabels.DEPLOY) | ||
| ? PrTriggerLabels.DEPLOY | ||
| : [PrTriggerLabels.DEPLOY]; | ||
| const updatedLabels = currentLabels.filter((label) => !deployLabelsToRemove.includes(label)); | ||
|
|
||
| await github.updatePullRequestLabels({ | ||
| installationId, | ||
| pullRequestNumber: number, | ||
| fullName, | ||
| labels: labels.map((l) => l.name).filter((v) => v !== Labels.DEPLOY), | ||
| labels: updatedLabels, | ||
| }); | ||
| } | ||
| } catch (error) { | ||
|
|
@@ -246,8 +274,8 @@ export default class GithubService extends Service { | |
| ); | ||
|
|
||
| if (pullRequest.deployOnUpdate === false) { | ||
| // when pullRequest.deployOnUpdate is false, it means that there is no `lifecycle-deploy!` label | ||
| // or there is `lifecycle-disabled!` label in the PR | ||
| // when pullRequest.deployOnUpdate is false, it means that there are no PrTriggerLabels.DEPLOY labels | ||
| // or there are PrTriggerLabels.DISABLED labels in the PR | ||
| return this.db.services.BuildService.deleteBuild(build); | ||
| } | ||
|
|
||
|
|
@@ -481,7 +509,10 @@ export default class GithubService extends Service { | |
| const branch = pullRequest?.branchName; | ||
| try { | ||
| const isBot = await this.db.services.BotUser.isBotUser(user); | ||
| const hasDeployLabel = labelNames.includes(Labels.DEPLOY); | ||
| const deployLabels = Array.isArray(PrTriggerLabels.DEPLOY) | ||
| ? PrTriggerLabels.DEPLOY.map((label) => label.toLowerCase()) | ||
| : [PrTriggerLabels.DEPLOY]; | ||
| const hasDeployLabel = labelNames.some((label) => deployLabels.includes(label)); | ||
| const isDeploy = hasDeployLabel || autoDeploy; | ||
| const isKillSwitch = await enableKillSwitch({ | ||
| isBotUser: isBot, | ||
|
|
||
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.
If labels is not an array, is the
PrTriggerLabels.DEPLOY.includes(labels);expression valid? Iflabelsis not an array and labels is equal to aDEPLOYlabel likelets-go!thenisDisabledwill resolve to true but that seems like it might be unexpected.should it be
PrTriggerLabels.DISABLED.includes(labels)instead?Uh oh!
There was an error while loading. Please reload this page.
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.
the enableKillSwitch function takes a labels value that defaults to an empty array...
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 what happens if your PR only has a single label and the single label is
let-it-go!?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.
in theory.... nothing should happen... ill test it
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 after a bit of testing the
let-it-go!label doesnt make sense since it just disabling auto-deply... ive update the label to reflect that and not use lifecycle wordage