Merge branch 'main' into main

This commit is contained in:
Cory Miller 2022-06-20 13:19:34 -04:00 committed by GitHub
commit 736a97ebc6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 3843 additions and 1431 deletions

View File

@ -4,9 +4,9 @@ updates:
- package-ecosystem: 'npm' - package-ecosystem: 'npm'
# Look for `package.json` and `lock` files in the `root` directory # Look for `package.json` and `lock` files in the `root` directory
directory: '/' directory: '/'
# Check the npm registry for updates every day (weekdays) # Check the npm registry for updates once a week (Monday)
schedule: schedule:
interval: 'daily' interval: 'weekly'
- package-ecosystem: 'github-actions' - package-ecosystem: 'github-actions'
directory: '/' directory: '/'

View File

@ -23,10 +23,10 @@ jobs:
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Set Node.js 12.x - name: Set Node.js 16.x
uses: actions/setup-node@v1 uses: actions/setup-node@v1
with: with:
node-version: 12.x node-version: 16.x
- name: Install dependencies - name: Install dependencies
run: npm ci run: npm ci

View File

@ -1103,7 +1103,7 @@ class IssuesProcessorBuilder {
issue.updated_at ?? new Date().toDateString(), issue.updated_at ?? new Date().toDateString(),
issue.created_at ?? new Date().toDateString(), issue.created_at ?? new Date().toDateString(),
!!issue.pull_request, !!issue.pull_request,
issue.labels ? issue.labels.map(label => label.name) : [] issue.labels ? issue.labels.map(label => label.name || '') : []
) )
); );

View File

@ -9,7 +9,7 @@ export class IssuesProcessorMock extends IssuesProcessor {
options: IIssuesProcessorOptions, options: IIssuesProcessorOptions,
getIssues?: (page: number) => Promise<Issue[]>, getIssues?: (page: number) => Promise<Issue[]>,
listIssueComments?: ( listIssueComments?: (
issueNumber: number, issue: Issue,
sinceDate: string sinceDate: string
) => Promise<IComment[]>, ) => Promise<IComment[]>,
getLabelCreationDate?: ( getLabelCreationDate?: (

View File

@ -85,7 +85,7 @@ class IssuesProcessorBuilder {
issue.updated_at ?? new Date().toDateString(), issue.updated_at ?? new Date().toDateString(),
issue.created_at ?? new Date().toDateString(), issue.created_at ?? new Date().toDateString(),
!!issue.pull_request, !!issue.pull_request,
issue.labels ? issue.labels.map(label => label.name) : [] issue.labels ? issue.labels.map(label => label.name || '') : []
) )
); );

View File

@ -1103,7 +1103,7 @@ class IssuesProcessorBuilder {
issue.updated_at ?? new Date().toDateString(), issue.updated_at ?? new Date().toDateString(),
issue.created_at ?? new Date().toDateString(), issue.created_at ?? new Date().toDateString(),
!!issue.pull_request, !!issue.pull_request,
issue.labels ? issue.labels.map(label => label.name) : [] issue.labels ? issue.labels.map(label => label.name || '') : []
) )
); );

View File

@ -455,7 +455,7 @@ class IssuesProcessorBuilder {
issue.updated_at ?? new Date().toDateString(), issue.updated_at ?? new Date().toDateString(),
issue.created_at ?? new Date().toDateString(), issue.created_at ?? new Date().toDateString(),
!!issue.pull_request, !!issue.pull_request,
issue.labels ? issue.labels.map(label => label.name) : [] issue.labels ? issue.labels.map(label => label.name || '') : []
) )
); );

View File

@ -198,5 +198,5 @@ outputs:
staled-issues-prs: staled-issues-prs:
description: 'List of all staled issues and pull requests.' description: 'List of all staled issues and pull requests.'
runs: runs:
using: 'node12' using: 'node16'
main: 'dist/index.js' main: 'dist/index.js'

3891
dist/index.js vendored

File diff suppressed because one or more lines are too long

1241
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -39,7 +39,7 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/core": "^1.2.6", "@actions/core": "^1.2.6",
"@actions/github": "^4.0.0", "@actions/github": "^5.0.1",
"lodash.deburr": "^4.1.0", "lodash.deburr": "^4.1.0",
"semver": "^7.3.5" "semver": "^7.3.5"
}, },
@ -56,7 +56,7 @@
"eslint-plugin-github": "^4.1.2", "eslint-plugin-github": "^4.1.2",
"eslint-plugin-jest": "^25.3.2", "eslint-plugin-jest": "^25.3.2",
"jest": "^27.2.5", "jest": "^27.2.5",
"jest-circus": "^27.2.0", "jest-circus": "^27.4.6",
"jest-silent-reporter": "^0.5.0", "jest-silent-reporter": "^0.5.0",
"js-yaml": "^4.1.0", "js-yaml": "^4.1.0",
"prettier": "^2.5.1", "prettier": "^2.5.1",

View File

@ -1,7 +1,7 @@
import {isLabeled} from '../functions/is-labeled'; import {isLabeled} from '../functions/is-labeled';
import {isPullRequest} from '../functions/is-pull-request'; import {isPullRequest} from '../functions/is-pull-request';
import {Assignee} from '../interfaces/assignee'; import {Assignee} from '../interfaces/assignee';
import {IIssue} from '../interfaces/issue'; import {IIssue, OctokitIssue} from '../interfaces/issue';
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options'; import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
import {ILabel} from '../interfaces/label'; import {ILabel} from '../interfaces/label';
import {IMilestone} from '../interfaces/milestone'; import {IMilestone} from '../interfaces/milestone';
@ -17,28 +17,30 @@ export class Issue implements IIssue {
readonly pull_request: Object | null | undefined; readonly pull_request: Object | null | undefined;
readonly state: string | 'closed' | 'open'; readonly state: string | 'closed' | 'open';
readonly locked: boolean; readonly locked: boolean;
readonly milestone: IMilestone | undefined; readonly milestone?: IMilestone | null;
readonly assignees: Assignee[]; readonly assignees: Assignee[];
isStale: boolean; isStale: boolean;
markedStaleThisRun: boolean;
operations = new Operations(); operations = new Operations();
private readonly _options: IIssuesProcessorOptions; private readonly _options: IIssuesProcessorOptions;
constructor( constructor(
options: Readonly<IIssuesProcessorOptions>, options: Readonly<IIssuesProcessorOptions>,
issue: Readonly<IIssue> issue: Readonly<OctokitIssue> | Readonly<IIssue>
) { ) {
this._options = options; this._options = options;
this.title = issue.title; this.title = issue.title;
this.number = issue.number; this.number = issue.number;
this.created_at = issue.created_at; this.created_at = issue.created_at;
this.updated_at = issue.updated_at; this.updated_at = issue.updated_at;
this.labels = issue.labels; this.labels = mapLabels(issue.labels);
this.pull_request = issue.pull_request; this.pull_request = issue.pull_request;
this.state = issue.state; this.state = issue.state;
this.locked = issue.locked; this.locked = issue.locked;
this.milestone = issue.milestone; this.milestone = issue.milestone;
this.assignees = issue.assignees; this.assignees = issue.assignees || [];
this.isStale = isLabeled(this, this.staleLabel); this.isStale = isLabeled(this, this.staleLabel);
this.markedStaleThisRun = false;
} }
get isPullRequest(): boolean { get isPullRequest(): boolean {
@ -59,3 +61,14 @@ export class Issue implements IIssue {
: this._options.staleIssueLabel; : this._options.staleIssueLabel;
} }
} }
function mapLabels(labels: (string | ILabel)[] | ILabel[]): ILabel[] {
return labels.map(label => {
if (typeof label == 'string') {
return {
name: label
};
}
return label;
});
}

View File

@ -1,7 +1,6 @@
import * as core from '@actions/core'; import * as core from '@actions/core';
import {context, getOctokit} from '@actions/github'; import {context, getOctokit} from '@actions/github';
import {GitHub} from '@actions/github/lib/utils'; import {GitHub} from '@actions/github/lib/utils';
import {GetResponseTypeFromEndpointMethod} from '@octokit/types';
import {Option} from '../enums/option'; import {Option} from '../enums/option';
import {getHumanizedDate} from '../functions/dates/get-humanized-date'; import {getHumanizedDate} from '../functions/dates/get-humanized-date';
import {isDateMoreRecentThan} from '../functions/dates/is-date-more-recent-than'; import {isDateMoreRecentThan} from '../functions/dates/is-date-more-recent-than';
@ -25,7 +24,7 @@ import {Milestones} from './milestones';
import {StaleOperations} from './stale-operations'; import {StaleOperations} from './stale-operations';
import {Statistics} from './statistics'; import {Statistics} from './statistics';
import {LoggerService} from '../services/logger.service'; import {LoggerService} from '../services/logger.service';
import {IIssue} from '../interfaces/issue'; import {OctokitIssue} from '../interfaces/issue';
/*** /***
* Handle processing of issues for staleness/closure. * Handle processing of issues for staleness/closure.
@ -466,6 +465,7 @@ export class IssuesProcessor {
); );
await this._markStale(issue, staleMessage, staleLabel, skipMessage); await this._markStale(issue, staleMessage, staleLabel, skipMessage);
issue.isStale = true; // This issue is now considered stale issue.isStale = true; // This issue is now considered stale
issue.markedStaleThisRun = true;
issueLogger.info(`This $$type is now stale`); issueLogger.info(`This $$type is now stale`);
} else { } else {
issueLogger.info( issueLogger.info(
@ -510,17 +510,17 @@ export class IssuesProcessor {
// Grab comments for an issue since a given date // Grab comments for an issue since a given date
async listIssueComments( async listIssueComments(
issueNumber: Readonly<number>, issue: Readonly<Issue>,
sinceDate: Readonly<string> sinceDate: Readonly<string>
): Promise<IComment[]> { ): Promise<IComment[]> {
// Find any comments since date on the given issue // Find any comments since date on the given issue
try { try {
this.operations.consumeOperation(); this._consumeIssueOperation(issue);
this.statistics?.incrementFetchedItemsCommentsCount(); this.statistics?.incrementFetchedItemsCommentsCount();
const comments = await this.client.issues.listComments({ const comments = await this.client.rest.issues.listComments({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
issue_number: issueNumber, issue_number: issue.number,
since: sinceDate since: sinceDate
}); });
return comments.data; return comments.data;
@ -532,25 +532,20 @@ export class IssuesProcessor {
// grab issues from github in batches of 100 // grab issues from github in batches of 100
async getIssues(page: number): Promise<Issue[]> { async getIssues(page: number): Promise<Issue[]> {
// generate type for response
const endpoint = this.client.issues.listForRepo;
type OctoKitIssueList = GetResponseTypeFromEndpointMethod<typeof endpoint>;
try { try {
this.operations.consumeOperation(); this.operations.consumeOperation();
const issueResult: OctoKitIssueList = const issueResult = await this.client.rest.issues.listForRepo({
await this.client.issues.listForRepo({ owner: context.repo.owner,
owner: context.repo.owner, repo: context.repo.repo,
repo: context.repo.repo, state: 'open',
state: 'open', per_page: 100,
per_page: 100, direction: this.options.ascending ? 'asc' : 'desc',
direction: this.options.ascending ? 'asc' : 'desc', page
page });
});
this.statistics?.incrementFetchedItemsCount(issueResult.data.length); this.statistics?.incrementFetchedItemsCount(issueResult.data.length);
return issueResult.data.map( return issueResult.data.map(
(issue: Readonly<IIssue>): Issue => new Issue(this.options, issue) (issue: Readonly<OctokitIssue>): Issue => new Issue(this.options, issue)
); );
} catch (error) { } catch (error) {
this._logger.error(`Get issues for repo error: ${error.message}`); this._logger.error(`Get issues for repo error: ${error.message}`);
@ -570,7 +565,7 @@ export class IssuesProcessor {
this._consumeIssueOperation(issue); this._consumeIssueOperation(issue);
this.statistics?.incrementFetchedItemsEventsCount(); this.statistics?.incrementFetchedItemsEventsCount();
const options = this.client.issues.listEvents.endpoint.merge({ const options = this.client.rest.issues.listEvents.endpoint.merge({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
per_page: 100, per_page: 100,
@ -601,7 +596,7 @@ export class IssuesProcessor {
this._consumeIssueOperation(issue); this._consumeIssueOperation(issue);
this.statistics?.incrementFetchedPullRequestsCount(); this.statistics?.incrementFetchedPullRequestsCount();
const pullRequest = await this.client.pulls.get({ const pullRequest = await this.client.rest.pulls.get({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
pull_number: issue.number pull_number: issue.number
@ -672,8 +667,16 @@ export class IssuesProcessor {
); );
} }
if (issue.markedStaleThisRun) {
issueLogger.info(`marked stale this run, so don't check for updates`);
}
// Should we un-stale this issue? // Should we un-stale this issue?
if (shouldRemoveStaleWhenUpdated && issueHasComments) { if (
shouldRemoveStaleWhenUpdated &&
issueHasComments &&
!issue.markedStaleThisRun
) {
issueLogger.info( issueLogger.info(
`Remove the stale label since the $$type has a comment and the workflow should remove the stale label when updated` `Remove the stale label since the $$type has a comment and the workflow should remove the stale label when updated`
); );
@ -734,12 +737,12 @@ export class IssuesProcessor {
} }
// find any comments since the date // find any comments since the date
const comments = await this.listIssueComments(issue.number, sinceDate); const comments = await this.listIssueComments(issue, sinceDate);
const filteredComments = comments.filter( const filteredComments = comments.filter(
comment => comment =>
comment.user.type === 'User' && comment.user?.type === 'User' &&
comment.body.toLowerCase() !== staleMessage.toLowerCase() comment.body?.toLowerCase() !== staleMessage.toLowerCase()
); );
issueLogger.info( issueLogger.info(
@ -775,7 +778,7 @@ export class IssuesProcessor {
this.statistics?.incrementAddedItemsComment(issue); this.statistics?.incrementAddedItemsComment(issue);
if (!this.options.debugOnly) { if (!this.options.debugOnly) {
await this.client.issues.createComment({ await this.client.rest.issues.createComment({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
issue_number: issue.number, issue_number: issue.number,
@ -793,7 +796,7 @@ export class IssuesProcessor {
this.statistics?.incrementStaleItemsCount(issue); this.statistics?.incrementStaleItemsCount(issue);
if (!this.options.debugOnly) { if (!this.options.debugOnly) {
await this.client.issues.addLabels({ await this.client.rest.issues.addLabels({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
issue_number: issue.number, issue_number: issue.number,
@ -823,7 +826,7 @@ export class IssuesProcessor {
this.addedCloseCommentIssues.push(issue); this.addedCloseCommentIssues.push(issue);
if (!this.options.debugOnly) { if (!this.options.debugOnly) {
await this.client.issues.createComment({ await this.client.rest.issues.createComment({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
issue_number: issue.number, issue_number: issue.number,
@ -841,7 +844,7 @@ export class IssuesProcessor {
this.statistics?.incrementAddedItemsLabel(issue); this.statistics?.incrementAddedItemsLabel(issue);
if (!this.options.debugOnly) { if (!this.options.debugOnly) {
await this.client.issues.addLabels({ await this.client.rest.issues.addLabels({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
issue_number: issue.number, issue_number: issue.number,
@ -858,7 +861,7 @@ export class IssuesProcessor {
this.statistics?.incrementClosedItemsCount(issue); this.statistics?.incrementClosedItemsCount(issue);
if (!this.options.debugOnly) { if (!this.options.debugOnly) {
await this.client.issues.update({ await this.client.rest.issues.update({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
issue_number: issue.number, issue_number: issue.number,
@ -900,7 +903,7 @@ export class IssuesProcessor {
this.statistics?.incrementDeletedBranchesCount(); this.statistics?.incrementDeletedBranchesCount();
if (!this.options.debugOnly) { if (!this.options.debugOnly) {
await this.client.git.deleteRef({ await this.client.rest.git.deleteRef({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
ref: `heads/${branch}` ref: `heads/${branch}`
@ -935,7 +938,7 @@ export class IssuesProcessor {
this.statistics?.incrementDeletedItemsLabelsCount(issue); this.statistics?.incrementDeletedItemsLabelsCount(issue);
if (!this.options.debugOnly) { if (!this.options.debugOnly) {
await this.client.issues.removeLabel({ await this.client.rest.issues.removeLabel({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
issue_number: issue.number, issue_number: issue.number,
@ -1065,10 +1068,10 @@ export class IssuesProcessor {
this.addedLabelIssues.push(issue); this.addedLabelIssues.push(issue);
try { try {
this.operations.consumeOperation(); this._consumeIssueOperation(issue);
this.statistics?.incrementAddedItemsLabel(issue); this.statistics?.incrementAddedItemsLabel(issue);
if (!this.options.debugOnly) { if (!this.options.debugOnly) {
await this.client.issues.addLabels({ await this.client.rest.issues.addLabels({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
issue_number: issue.number, issue_number: issue.number,

View File

@ -9,6 +9,6 @@ import {CleanLabel} from '../types/clean-label';
* *
* @return {string} A lowercased, deburred version of the passed in label * @return {string} A lowercased, deburred version of the passed in label
*/ */
export function cleanLabel(label: Readonly<string>): CleanLabel { export function cleanLabel(label?: Readonly<string>): CleanLabel {
return deburr(label.toLowerCase()); return deburr(label?.toLowerCase());
} }

View File

@ -1,6 +1,6 @@
import {IUser} from './user'; import {IUser} from './user';
export interface IComment { export interface IComment {
user: IUser; user: IUser | null;
body: string; body?: string;
} }

View File

@ -2,16 +2,18 @@ import {IsoDateString} from '../types/iso-date-string';
import {Assignee} from './assignee'; import {Assignee} from './assignee';
import {ILabel} from './label'; import {ILabel} from './label';
import {IMilestone} from './milestone'; import {IMilestone} from './milestone';
import {components} from '@octokit/openapi-types';
export interface IIssue { export interface IIssue {
title: string; title: string;
number: number; number: number;
created_at: IsoDateString; created_at: IsoDateString;
updated_at: IsoDateString; updated_at: IsoDateString;
labels: ILabel[]; labels: ILabel[];
pull_request: Object | null | undefined; pull_request?: Object | null;
state: string; state: string;
locked: boolean; locked: boolean;
milestone: IMilestone | undefined; milestone?: IMilestone | null;
assignees: Assignee[]; assignees?: Assignee[] | null;
} }
export type OctokitIssue = components['schemas']['issue'];

View File

@ -1,3 +1,3 @@
export interface ILabel { export interface ILabel {
name: string; name?: string;
} }

View File

@ -3,5 +3,5 @@ export interface IPullRequest {
head: { head: {
ref: string; ref: string;
}; };
draft: boolean; draft?: boolean;
} }