mirror of
https://github.com/actions/stale.git
synced 2025-12-11 12:37:27 +00:00
Determine actor from PAT if possible (#231)
This commit is contained in:
@@ -80,6 +80,7 @@ export class IssueProcessor {
|
||||
|
||||
constructor(
|
||||
options: IssueProcessorOptions,
|
||||
getActor?: () => Promise<string>,
|
||||
getIssues?: (page: number) => Promise<Issue[]>,
|
||||
listIssueComments?: (
|
||||
issueNumber: number,
|
||||
@@ -94,6 +95,10 @@ export class IssueProcessor {
|
||||
this.operationsLeft = options.operationsPerRun;
|
||||
this.client = getOctokit(options.repoToken);
|
||||
|
||||
if (getActor) {
|
||||
this.getActor = getActor;
|
||||
}
|
||||
|
||||
if (getIssues) {
|
||||
this.getIssues = getIssues;
|
||||
}
|
||||
@@ -118,6 +123,8 @@ export class IssueProcessor {
|
||||
const issues: Issue[] = await this.getIssues(page);
|
||||
this.operationsLeft -= 1;
|
||||
|
||||
const actor: string = await this.getActor();
|
||||
|
||||
if (issues.length <= 0) {
|
||||
core.info('No more issues found to process. Exiting.');
|
||||
return this.operationsLeft;
|
||||
@@ -207,6 +214,7 @@ export class IssueProcessor {
|
||||
issue,
|
||||
issueType,
|
||||
staleLabel,
|
||||
actor,
|
||||
closeMessage,
|
||||
closeLabel
|
||||
);
|
||||
@@ -227,6 +235,7 @@ export class IssueProcessor {
|
||||
issue: Issue,
|
||||
issueType: string,
|
||||
staleLabel: string,
|
||||
actor: string,
|
||||
closeMessage?: string,
|
||||
closeLabel?: string
|
||||
) {
|
||||
@@ -236,7 +245,8 @@ export class IssueProcessor {
|
||||
|
||||
const issueHasComments: boolean = await this.hasCommentsSince(
|
||||
issue,
|
||||
markedStaleOn
|
||||
markedStaleOn,
|
||||
actor
|
||||
);
|
||||
core.info(
|
||||
`Issue #${issue.number} has been commented on: ${issueHasComments}`
|
||||
@@ -284,7 +294,8 @@ export class IssueProcessor {
|
||||
// checks to see if a given issue is still stale (has had activity on it)
|
||||
private async hasCommentsSince(
|
||||
issue: Issue,
|
||||
sinceDate: string
|
||||
sinceDate: string,
|
||||
actor: string
|
||||
): Promise<boolean> {
|
||||
core.info(
|
||||
`Checking for comments on issue #${issue.number} since ${sinceDate}`
|
||||
@@ -299,7 +310,7 @@ export class IssueProcessor {
|
||||
|
||||
const filteredComments = comments.filter(
|
||||
comment =>
|
||||
comment.user.type === 'User' && comment.user.login !== context.actor
|
||||
comment.user.type === 'User' && comment.user.login !== actor
|
||||
);
|
||||
|
||||
core.info(
|
||||
@@ -330,6 +341,18 @@ export class IssueProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
// get the actor from the GitHub token or context
|
||||
private async getActor(): Promise<string> {
|
||||
let actor;
|
||||
try {
|
||||
actor = await this.client.users.getAuthenticated();
|
||||
} catch (error) {
|
||||
return context.actor
|
||||
}
|
||||
|
||||
return actor.data.login
|
||||
}
|
||||
|
||||
// grab issues from github in baches of 100
|
||||
private async getIssues(page: number): Promise<Issue[]> {
|
||||
// generate type for response
|
||||
|
||||
Reference in New Issue
Block a user