mirror of
https://github.com/actions/stale.git
synced 2025-12-25 17:58:17 +00:00
Compare commits
3 Commits
v3.0.5
...
handle_api
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
06fc759d9f | ||
|
|
65bccdf399 | ||
|
|
c72e3d7ff2 |
2188
dist/index.js
vendored
2188
dist/index.js
vendored
File diff suppressed because it is too large
Load Diff
@@ -203,7 +203,7 @@ export class IssueProcessor {
|
|||||||
|
|
||||||
const issueHasUpdate: boolean = IssueProcessor.updatedSince(
|
const issueHasUpdate: boolean = IssueProcessor.updatedSince(
|
||||||
issue.updated_at,
|
issue.updated_at,
|
||||||
this.options.daysBeforeClose + (this.options.daysBeforeStale ?? 0)
|
this.options.daysBeforeClose
|
||||||
);
|
);
|
||||||
core.info(`Issue #${issue.number} has been updated: ${issueHasUpdate}`);
|
core.info(`Issue #${issue.number} has been updated: ${issueHasUpdate}`);
|
||||||
|
|
||||||
@@ -268,28 +268,38 @@ export class IssueProcessor {
|
|||||||
sinceDate: string
|
sinceDate: string
|
||||||
): Promise<Comment[]> {
|
): Promise<Comment[]> {
|
||||||
// find any comments since date on the given issue
|
// find any comments since date on the given issue
|
||||||
const comments = await this.client.issues.listComments({
|
try {
|
||||||
owner: github.context.repo.owner,
|
const comments = await this.client.issues.listComments({
|
||||||
repo: github.context.repo.repo,
|
owner: github.context.repo.owner,
|
||||||
issue_number: issueNumber,
|
repo: github.context.repo.repo,
|
||||||
since: sinceDate
|
issue_number: issueNumber,
|
||||||
});
|
since: sinceDate
|
||||||
|
});
|
||||||
return comments.data;
|
return comments.data;
|
||||||
|
} catch (error) {
|
||||||
|
core.error(`List issue comments error: ${error.message}`);
|
||||||
|
return Promise.resolve([]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// grab issues from github in baches of 100
|
// grab issues from github in baches of 100
|
||||||
private async getIssues(page: number): Promise<Issue[]> {
|
private async getIssues(page: number): Promise<Issue[]> {
|
||||||
const issueResult: OctoKitIssueList = await this.client.issues.listForRepo({
|
try {
|
||||||
owner: github.context.repo.owner,
|
const issueResult: OctoKitIssueList = await this.client.issues.listForRepo(
|
||||||
repo: github.context.repo.repo,
|
{
|
||||||
state: 'open',
|
owner: github.context.repo.owner,
|
||||||
labels: this.options.onlyLabels,
|
repo: github.context.repo.repo,
|
||||||
per_page: 100,
|
state: 'open',
|
||||||
page
|
labels: this.options.onlyLabels,
|
||||||
});
|
per_page: 100,
|
||||||
|
page
|
||||||
return issueResult.data;
|
}
|
||||||
|
);
|
||||||
|
return issueResult.data;
|
||||||
|
} catch (error) {
|
||||||
|
core.error(`Get issues for repo error: ${error.message}`);
|
||||||
|
return Promise.resolve([]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark an issue as stale with a comment and a label
|
// Mark an issue as stale with a comment and a label
|
||||||
@@ -304,37 +314,36 @@ export class IssueProcessor {
|
|||||||
|
|
||||||
this.operationsLeft -= 2;
|
this.operationsLeft -= 2;
|
||||||
|
|
||||||
// We are about to modify the issue by adding a comment and applying a label, so update the modification timestamp
|
// if the issue is being marked stale, the updated date should be changed to right now
|
||||||
// to `days-before-stale` days ago to simulate as if we marked this issue stale on the very first day it actually
|
// so that close calculations work correctly
|
||||||
// became stale. This has the effect of respecting `days-before-close` no matter what value it is set to. The user
|
|
||||||
// can request to close the issue immediately by using `days-before-close` === 0, or they can set it to any number
|
|
||||||
// of days to wait before actually closing the issue.
|
|
||||||
const daysBeforeStaleInMillis =
|
|
||||||
1000 * 60 * 60 * 24 * this.options.daysBeforeStale;
|
|
||||||
const newUpdatedAtDate: Date = new Date();
|
const newUpdatedAtDate: Date = new Date();
|
||||||
newUpdatedAtDate.setTime(
|
|
||||||
newUpdatedAtDate.getTime() - daysBeforeStaleInMillis
|
|
||||||
);
|
|
||||||
|
|
||||||
issue.updated_at = newUpdatedAtDate.toString();
|
issue.updated_at = newUpdatedAtDate.toString();
|
||||||
|
|
||||||
if (this.options.debugOnly) {
|
if (this.options.debugOnly) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.client.issues.createComment({
|
try {
|
||||||
owner: github.context.repo.owner,
|
await this.client.issues.createComment({
|
||||||
repo: github.context.repo.repo,
|
owner: github.context.repo.owner,
|
||||||
issue_number: issue.number,
|
repo: github.context.repo.repo,
|
||||||
body: staleMessage
|
issue_number: issue.number,
|
||||||
});
|
body: staleMessage
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
core.error(`Error creating a comment: ${error.message}`);
|
||||||
|
}
|
||||||
|
|
||||||
await this.client.issues.addLabels({
|
try {
|
||||||
owner: github.context.repo.owner,
|
await this.client.issues.addLabels({
|
||||||
repo: github.context.repo.repo,
|
owner: github.context.repo.owner,
|
||||||
issue_number: issue.number,
|
repo: github.context.repo.repo,
|
||||||
labels: [staleLabel]
|
issue_number: issue.number,
|
||||||
});
|
labels: [staleLabel]
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
core.error(`Error adding a label: ${error.message}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close an issue based on staleness
|
// Close an issue based on staleness
|
||||||
@@ -351,12 +360,16 @@ export class IssueProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.client.issues.update({
|
try {
|
||||||
owner: github.context.repo.owner,
|
await this.client.issues.update({
|
||||||
repo: github.context.repo.repo,
|
owner: github.context.repo.owner,
|
||||||
issue_number: issue.number,
|
repo: github.context.repo.repo,
|
||||||
state: 'closed'
|
issue_number: issue.number,
|
||||||
});
|
state: 'closed'
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
core.error(`Error updating an issue: ${error.message}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove a label from an issue
|
// Remove a label from an issue
|
||||||
@@ -373,12 +386,16 @@ export class IssueProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.client.issues.removeLabel({
|
try {
|
||||||
owner: github.context.repo.owner,
|
await this.client.issues.removeLabel({
|
||||||
repo: github.context.repo.repo,
|
owner: github.context.repo.owner,
|
||||||
issue_number: issue.number,
|
repo: github.context.repo.repo,
|
||||||
name: encodeURIComponent(label) // A label can have a "?" in the name
|
issue_number: issue.number,
|
||||||
});
|
name: encodeURIComponent(label) // A label can have a "?" in the name
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
core.error(`Error removing a label: ${error.message}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns the creation date of a given label on an issue (or nothing if no label existed)
|
// returns the creation date of a given label on an issue (or nothing if no label existed)
|
||||||
|
|||||||
Reference in New Issue
Block a user