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

Enhance issue commands to assign all projects at once #225

Merged
merged 7 commits into from
Sep 13, 2024
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
17 changes: 13 additions & 4 deletions commands/Commands.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 26 additions & 8 deletions commands/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ export type Command = { name: string } & (
| { type: 'comment'; allowUsers: string[] }
| { type: 'label' }
| { type: 'changedfiles'; matches: string | string[] | { any: string[] } | { all: string[] } }
| { type: 'author'; memberOf?: { org: string }; notMemberOf?: { org: string }; ignoreList?: string[]; noLabels?: boolean }
| {
academo marked this conversation as resolved.
Show resolved Hide resolved
type: 'author'
memberOf?: { org: string }
notMemberOf?: { org: string }
ignoreList?: string[]
noLabels?: boolean
}
) & {
action?: 'close' | 'addToProject' | 'removeFromProject'
} & Partial<{ comment: string; addLabel: string; removeLabel: string }> &
Partial<{ requireLabel: string; disallowLabel: string }>
& Partial<{ addToProject: { url: string, org?: string, column?: string } }>
& Partial<{ removeFromProject: { url: string, org?: string } }>
Partial<{ requireLabel: string; disallowLabel: string }> &
Partial<{ addToProject: { url: string; org?: string; column?: string } }> &
Partial<{ removeFromProject: { url: string; org?: string } }>
/* eslint-enable */

export class Commands {
Expand Down Expand Up @@ -96,15 +102,25 @@ export class Commands {
}
}

if ('label' in this.action) {
return command.type === 'label' && this.action.label === command.name
if ('label' in this.action && command.type === 'label' && this.action.label === command.name) {
academo marked this conversation as resolved.
Show resolved Hide resolved
return true
}

// If the command is a label, the issue has the label and the action is addToProject, execute the command
// This is to allow the pipeline to add multiple projects at once based on all the issue labels
if (
command.type === 'label' &&
command.action === 'addToProject' &&
issue.labels.includes(command.name)
) {
return true
}

return false
}

private async perform(command: Command, issue: Issue, changedFiles: string[]) {
console.debug('Would perform command:', command, ' on issue:', issue)
console.debug('Would try to perform command:', command, ' on issue:', issue)
if (!(await this.matches(command, issue, changedFiles))) {
console.debug('Command ', JSON.stringify(command), ' did not match any criteria')
return
Expand Down Expand Up @@ -233,7 +249,9 @@ export class Commands {
console.log('Found changedfiles commands, listing pull request filenames...')
changedFiles = await this.github.listPullRequestFilenames()
}
console.debug('Would perform commands:', this.config)
console.debug('----- Current Commands configuration -----')
console.debug(this.config)
console.debug('----- End of Commands configuration -----')
return Promise.all(this.config.map((command) => this.perform(command, issue, changedFiles)))
}
}
Expand Down
Loading