Skip to content

Commit

Permalink
fix: remove and the labels as expected for update or comment when uns…
Browse files Browse the repository at this point in the history
…tale
  • Loading branch information
C0ZEN committed Jul 18, 2021
1 parent f6c3510 commit a8f503a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 10 deletions.
48 changes: 46 additions & 2 deletions __tests__/main.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@ test('stale label should be removed if a comment was added to a stale issue', as
expect(processor.removedLabelIssues).toHaveLength(1);
});

test('when the option "labelsToAddWhenUnstale" is set, the labels should be added when unstale', async () => {
test('when the option "labelsToAddWhenUnstale" is set, the labels should be added when unstale due to added comment', async () => {
expect.assertions(4);
const opts = {
...DefaultProcessorOptions,
Expand All @@ -1226,7 +1226,51 @@ test('when the option "labelsToAddWhenUnstale" is set, the labels should be adde
opts,
1,
'An issue that should have labels added to it when unstale',
new Date().toDateString(),
'2020-01-01T17:00:00Z',
false,
['Stale']
)
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [
{
user: {
login: 'notme',
type: 'User'
}
}
], // return a fake comment to indicate there was an update
async () => new Date().toDateString()
);

// process our fake issue list
await processor.processIssues(1);

expect(processor.closedIssues).toHaveLength(0);
expect(processor.staleIssues).toHaveLength(0);
// Stale should have been removed
expect(processor.removedLabelIssues).toHaveLength(1);
// Some label should have been added
expect(processor.addedLabelIssues).toHaveLength(1);
});

test('when the option "labelsToAddWhenUnstale" is set, the labels should be added when unstale due to update', async () => {
expect.assertions(4);
const opts = {
...DefaultProcessorOptions,
removeStaleWhenUpdated: true,
labelsToAddWhenUnstale: 'test'
};
const TestIssueList: Issue[] = [
generateIssue(
opts,
1,
'An issue that should have labels added to it when unstale',
new Date().toDateString(),
'2020-01-01T17:00:00Z',
false,
['Stale']
Expand Down Expand Up @@ -2312,7 +2356,7 @@ test('processing an issue stale since less than the daysBeforeStale without a st
expect(processor.closedIssues).toHaveLength(0);
});

test('processing an issue unstale that should be stale should not unstale and should keep the stale label added', async () => {
test('processing an issue unstale that should be stale should not unstale once again and should keep the stale label added when processing it for unstale', async () => {
expect.assertions(3);
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
Expand Down
14 changes: 6 additions & 8 deletions src/classes/issues-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -621,26 +621,24 @@ export class IssuesProcessor {
}

issueLogger.info(`Checking if the stale label should be removed...`);
let shouldRemoveStaleLabel = false;

// Should we un-stale this issue?
if (shouldRemoveStaleWhenUpdated && issueHasUpdate) {
issueLogger.info(
LoggerService.white('├── '),
`Remove the stale label since the $$type has an update and the workflow should remove the stale label when updated`
);
await this._removeStaleLabel(issue, staleLabel, true);

issueLogger.info(
LoggerService.white('└── '),
`Skipping the process since the $$type is now un-stale`
);

return; // Nothing to do because it is no longer stale
shouldRemoveStaleLabel = true;
} else if (shouldRemoveStaleWhenCommented && issueHasComments) {
issueLogger.info(
LoggerService.white('├── '),
`Remove the stale label since the $$type has a comment and the workflow should remove the stale label when commented`
);
shouldRemoveStaleLabel = true;
}

if (shouldRemoveStaleLabel) {
await this._removeStaleLabel(issue, staleLabel, true);

issueLogger.info(
Expand Down

0 comments on commit a8f503a

Please sign in to comment.