Skip to content

Commit

Permalink
Enhance issue commands to assign all projects at once (#225)
Browse files Browse the repository at this point in the history
* Improve logging

* add other projects when processing a single label

* Update

* improve logging

* fix logic error

* Add comments

* move back
  • Loading branch information
academo authored Sep 13, 2024
1 parent 008c799 commit befe2ea
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
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 }
| {
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) {
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

0 comments on commit befe2ea

Please sign in to comment.