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
Add support for adding & removing labels when no longer stale #468
Add support for adding & removing labels when no longer stale #468
Conversation
src/classes/issues-processor.ts
Outdated
`Adding labels marked as add-labels-when-updated-from-stale...` | ||
); | ||
|
||
this._statistics?.incrementAddedItemsLabel(issue); |
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.
Not sure if this is the statistic to increment
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.
This is a statistic to reflect a call to GitHub to add (one or multiple - we don't care since it's an array) a label to an issue/PR, so it seems OK to me, but I will have a better insight once I reviewed it.
src/classes/issues-processor.ts
Outdated
@@ -399,6 +402,8 @@ export class IssuesProcessor { | |||
issue, | |||
staleLabel, |
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.
You need to update the readme as well
src/classes/issues-processor.ts
Outdated
@@ -571,6 +578,10 @@ export class IssuesProcessor { | |||
if (this._shouldRemoveStaleWhenUpdated(issue) && issueHasComments) { | |||
await this._removeStaleLabel(issue, staleLabel); | |||
|
|||
// Are there labels to remove or add when an issue is no longer stale? | |||
await this._removeLabelsWhenUpdatedFromStale(issue, removeLabelsWhenUpdatedFromStale); |
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.
It's nice to defer the logic to reduce the complexity of this file.
One thing that could maybe be even better is to completely defer it to a dedicated class/service like milestones and assignees works.
src/classes/issues-processor.ts
Outdated
@@ -911,6 +922,48 @@ export class IssuesProcessor { | |||
return this.options.removeStaleWhenUpdated; | |||
} | |||
|
|||
private async _removeLabelsWhenUpdatedFromStale( | |||
issue: Issue, | |||
labels: Readonly<string>[] |
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.
labels: Readonly<string>[] | |
labels: ReadonlyArray<string> |
); | ||
|
||
for (const label of labels.values()) { | ||
await this._removeLabel(issue, label); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
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.
Unless I'm missing something, it doesn't look like there's a single method for that: https://docs.github.com/en/rest/reference/issues#labels
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.
Indeed.
In that case, it would be nice I think to explicitly mention in the readme when describing the option that it will consume one operation per label removal, and it's to use carefully. WDYT?
src/classes/issues-processor.ts
Outdated
} | ||
} | ||
|
||
private async _addLabelsWhenUpdatedFromStale( |
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.
Add tests, please?
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.
See #468 (comment), I should have replied to this comment.
src/classes/issues-processor.ts
Outdated
|
||
private async _addLabelsWhenUpdatedFromStale( | ||
issue: Issue, | ||
addLabels: Readonly<string>[] |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
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.
Not sure if we can modify the parameter this is passing into, but changing it to a ReadonlyArray gets type complaints: `The type 'readonly string[]' is 'readonly' and cannot be assigned to the mutable type 'string[]'.'
I noticed there was no easy way to check if specific labels were added / removed from issues, so I kept the "make sure some label was added to an issue" test similar to the others, where it just checks that an issue had a label added to it when we unstale it. It's harder to do that for unstale-issue-has-label-removed without redesigning some of the code, which is more than I'd like to chew. I could add a test that removes a label on unstale and check if the array that contains "issues that had labels removed from them" contains two issues (_removeLabel was called twice and therefore added the same item twice), but it's not ideal. |
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.
Good work @benvillalobos! Let's get the README updated with the new options. I also left a comment about naming.
@@ -47,4 +47,6 @@ export interface IIssuesProcessorOptions { | |||
exemptAllIssueAssignees: boolean | undefined; | |||
exemptAllPrAssignees: boolean | undefined; | |||
enableStatistics: boolean; | |||
removeLabelsWhenUnstale: string; |
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.
I don't want to be too picky on naming, but I wonder if a name like labelsToRemoveWhenUnstale
would read a little better and indicate that this option is a list of labels. To me removeLabelsWhenUnstale
reads like it should be a boolean
option. Not a huge deal either way, but curious what your thoughts are on that? @benvillalobos @C0ZEN
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.
reads like it should be a boolean option
I agree, and that makes sense considering I followed the naming scheme from removeIssueStaleWhenUpdated
😄 will rename.
ca82ec2
to
6389ef2
Compare
@benvillalobos you need to commit all those changes (probably due to a recent npm i which updated deps due to unpinned dependencies). |
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.
Almost done mate!
@@ -944,6 +959,65 @@ export class IssuesProcessor { | |||
return this.options.removeStaleWhenUpdated; | |||
} | |||
|
|||
private async _removeLabelsWhenUnstale( | |||
issue: Issue, | |||
removeLabels: Readonly<string>[] |
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.
removeLabels: Readonly<string>[] | |
labels: Readonly<string>[] |
src/classes/issues-processor.ts
Outdated
|
||
private async _addLabelsWhenUnstale( | ||
issue: Issue, | ||
addLabels: Readonly<string>[] |
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.
addLabels: Readonly<string>[] | |
labels: Readonly<string>[] |
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.
haven't been ignoring this suggestion. Trying to keep the var's name as labels
would result in an error passing labels: labels
when calling the API, presumably because the names were identical.
src/classes/issues-processor.ts
Outdated
|
||
this.addedLabelIssues.push(issue); | ||
|
||
if (this.options.debugOnly) { |
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.
Since the merge of this one #463
This check can now be closer to the GitHub call.
Basically, you can move the if from here to just around "addLabels".
That way, we have a better debugger and we can test the operations per run.
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.
@benvillalobos some conflicts FYI |
…fy arguments to remove ambiguity in 'labels' var & parameter
Co-authored-by: Geoffrey Testelin <geoffrey.testelin@gmail.com>
87fbc5e
to
272bf5f
Compare
@@ -299,14 +300,16 @@ class IssuesProcessor { | |||
else { | |||
this._logger.info(`${logger_service_1.LoggerService.yellow('Processing the batch of issues')} ${logger_service_1.LoggerService.cyan(`#${page}`)} ${logger_service_1.LoggerService.yellow('containing')} ${logger_service_1.LoggerService.cyan(issues.length)} ${logger_service_1.LoggerService.yellow(`issue${issues.length > 1 ? 's' : ''}...`)}`); | |||
} | |||
const labelsToAddWhenUnstale = words_to_list_1.wordsToList(this.options.labelsToAddWhenUnstale); |
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.
Is it reasonable to add this var as a global and have it set once via the constructor? I'm not a fan of changing the args to processIssue
to pass labels to add/remove when unstale. Not the most familiar with best practices in ts though.
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.
Great work @benvillalobos!
Thanks @luketomlinson! And thanks for the help shepherding this along @C0ZEN ! |
Seems like this wasn't enabled in the action.yml: #551 |
Fixes #460
Changes
Add support for:
Context
In order to prevent scenarios like this and to reduce the amount of upkeep required for maintainers, allow the action to remove/add labels to prevent marking issues stale over and over again.
Example of an ideal scenario is this:
needs-author-feedback
label and add someauthor-responded
orneeds-dev-response
labelThis allows automation to ONLY run on
needs-author-feedback
issues, or be exempt onauthor-responded
issues.