Merge branch 'main' into main
This commit is contained in:
commit
736a97ebc6
|
@ -4,9 +4,9 @@ updates:
|
|||
- package-ecosystem: 'npm'
|
||||
# Look for `package.json` and `lock` files in the `root` directory
|
||||
directory: '/'
|
||||
# Check the npm registry for updates every day (weekdays)
|
||||
# Check the npm registry for updates once a week (Monday)
|
||||
schedule:
|
||||
interval: 'daily'
|
||||
interval: 'weekly'
|
||||
|
||||
- package-ecosystem: 'github-actions'
|
||||
directory: '/'
|
||||
|
|
|
@ -23,10 +23,10 @@ jobs:
|
|||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Set Node.js 12.x
|
||||
- name: Set Node.js 16.x
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 12.x
|
||||
node-version: 16.x
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
|
|
@ -1103,7 +1103,7 @@ class IssuesProcessorBuilder {
|
|||
issue.updated_at ?? new Date().toDateString(),
|
||||
issue.created_at ?? new Date().toDateString(),
|
||||
!!issue.pull_request,
|
||||
issue.labels ? issue.labels.map(label => label.name) : []
|
||||
issue.labels ? issue.labels.map(label => label.name || '') : []
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ export class IssuesProcessorMock extends IssuesProcessor {
|
|||
options: IIssuesProcessorOptions,
|
||||
getIssues?: (page: number) => Promise<Issue[]>,
|
||||
listIssueComments?: (
|
||||
issueNumber: number,
|
||||
issue: Issue,
|
||||
sinceDate: string
|
||||
) => Promise<IComment[]>,
|
||||
getLabelCreationDate?: (
|
||||
|
|
|
@ -85,7 +85,7 @@ class IssuesProcessorBuilder {
|
|||
issue.updated_at ?? new Date().toDateString(),
|
||||
issue.created_at ?? new Date().toDateString(),
|
||||
!!issue.pull_request,
|
||||
issue.labels ? issue.labels.map(label => label.name) : []
|
||||
issue.labels ? issue.labels.map(label => label.name || '') : []
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
@ -1103,7 +1103,7 @@ class IssuesProcessorBuilder {
|
|||
issue.updated_at ?? new Date().toDateString(),
|
||||
issue.created_at ?? new Date().toDateString(),
|
||||
!!issue.pull_request,
|
||||
issue.labels ? issue.labels.map(label => label.name) : []
|
||||
issue.labels ? issue.labels.map(label => label.name || '') : []
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
@ -455,7 +455,7 @@ class IssuesProcessorBuilder {
|
|||
issue.updated_at ?? new Date().toDateString(),
|
||||
issue.created_at ?? new Date().toDateString(),
|
||||
!!issue.pull_request,
|
||||
issue.labels ? issue.labels.map(label => label.name) : []
|
||||
issue.labels ? issue.labels.map(label => label.name || '') : []
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
@ -198,5 +198,5 @@ outputs:
|
|||
staled-issues-prs:
|
||||
description: 'List of all staled issues and pull requests.'
|
||||
runs:
|
||||
using: 'node12'
|
||||
using: 'node16'
|
||||
main: 'dist/index.js'
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
|
@ -39,7 +39,7 @@
|
|||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.6",
|
||||
"@actions/github": "^4.0.0",
|
||||
"@actions/github": "^5.0.1",
|
||||
"lodash.deburr": "^4.1.0",
|
||||
"semver": "^7.3.5"
|
||||
},
|
||||
|
@ -56,7 +56,7 @@
|
|||
"eslint-plugin-github": "^4.1.2",
|
||||
"eslint-plugin-jest": "^25.3.2",
|
||||
"jest": "^27.2.5",
|
||||
"jest-circus": "^27.2.0",
|
||||
"jest-circus": "^27.4.6",
|
||||
"jest-silent-reporter": "^0.5.0",
|
||||
"js-yaml": "^4.1.0",
|
||||
"prettier": "^2.5.1",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import {isLabeled} from '../functions/is-labeled';
|
||||
import {isPullRequest} from '../functions/is-pull-request';
|
||||
import {Assignee} from '../interfaces/assignee';
|
||||
import {IIssue} from '../interfaces/issue';
|
||||
import {IIssue, OctokitIssue} from '../interfaces/issue';
|
||||
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
|
||||
import {ILabel} from '../interfaces/label';
|
||||
import {IMilestone} from '../interfaces/milestone';
|
||||
|
@ -17,28 +17,30 @@ export class Issue implements IIssue {
|
|||
readonly pull_request: Object | null | undefined;
|
||||
readonly state: string | 'closed' | 'open';
|
||||
readonly locked: boolean;
|
||||
readonly milestone: IMilestone | undefined;
|
||||
readonly milestone?: IMilestone | null;
|
||||
readonly assignees: Assignee[];
|
||||
isStale: boolean;
|
||||
markedStaleThisRun: boolean;
|
||||
operations = new Operations();
|
||||
private readonly _options: IIssuesProcessorOptions;
|
||||
|
||||
constructor(
|
||||
options: Readonly<IIssuesProcessorOptions>,
|
||||
issue: Readonly<IIssue>
|
||||
issue: Readonly<OctokitIssue> | Readonly<IIssue>
|
||||
) {
|
||||
this._options = options;
|
||||
this.title = issue.title;
|
||||
this.number = issue.number;
|
||||
this.created_at = issue.created_at;
|
||||
this.updated_at = issue.updated_at;
|
||||
this.labels = issue.labels;
|
||||
this.labels = mapLabels(issue.labels);
|
||||
this.pull_request = issue.pull_request;
|
||||
this.state = issue.state;
|
||||
this.locked = issue.locked;
|
||||
this.milestone = issue.milestone;
|
||||
this.assignees = issue.assignees;
|
||||
this.assignees = issue.assignees || [];
|
||||
this.isStale = isLabeled(this, this.staleLabel);
|
||||
this.markedStaleThisRun = false;
|
||||
}
|
||||
|
||||
get isPullRequest(): boolean {
|
||||
|
@ -59,3 +61,14 @@ export class Issue implements IIssue {
|
|||
: this._options.staleIssueLabel;
|
||||
}
|
||||
}
|
||||
|
||||
function mapLabels(labels: (string | ILabel)[] | ILabel[]): ILabel[] {
|
||||
return labels.map(label => {
|
||||
if (typeof label == 'string') {
|
||||
return {
|
||||
name: label
|
||||
};
|
||||
}
|
||||
return label;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import * as core from '@actions/core';
|
||||
import {context, getOctokit} from '@actions/github';
|
||||
import {GitHub} from '@actions/github/lib/utils';
|
||||
import {GetResponseTypeFromEndpointMethod} from '@octokit/types';
|
||||
import {Option} from '../enums/option';
|
||||
import {getHumanizedDate} from '../functions/dates/get-humanized-date';
|
||||
import {isDateMoreRecentThan} from '../functions/dates/is-date-more-recent-than';
|
||||
|
@ -25,7 +24,7 @@ import {Milestones} from './milestones';
|
|||
import {StaleOperations} from './stale-operations';
|
||||
import {Statistics} from './statistics';
|
||||
import {LoggerService} from '../services/logger.service';
|
||||
import {IIssue} from '../interfaces/issue';
|
||||
import {OctokitIssue} from '../interfaces/issue';
|
||||
|
||||
/***
|
||||
* Handle processing of issues for staleness/closure.
|
||||
|
@ -466,6 +465,7 @@ export class IssuesProcessor {
|
|||
);
|
||||
await this._markStale(issue, staleMessage, staleLabel, skipMessage);
|
||||
issue.isStale = true; // This issue is now considered stale
|
||||
issue.markedStaleThisRun = true;
|
||||
issueLogger.info(`This $$type is now stale`);
|
||||
} else {
|
||||
issueLogger.info(
|
||||
|
@ -510,17 +510,17 @@ export class IssuesProcessor {
|
|||
|
||||
// Grab comments for an issue since a given date
|
||||
async listIssueComments(
|
||||
issueNumber: Readonly<number>,
|
||||
issue: Readonly<Issue>,
|
||||
sinceDate: Readonly<string>
|
||||
): Promise<IComment[]> {
|
||||
// Find any comments since date on the given issue
|
||||
try {
|
||||
this.operations.consumeOperation();
|
||||
this._consumeIssueOperation(issue);
|
||||
this.statistics?.incrementFetchedItemsCommentsCount();
|
||||
const comments = await this.client.issues.listComments({
|
||||
const comments = await this.client.rest.issues.listComments({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: issueNumber,
|
||||
issue_number: issue.number,
|
||||
since: sinceDate
|
||||
});
|
||||
return comments.data;
|
||||
|
@ -532,25 +532,20 @@ export class IssuesProcessor {
|
|||
|
||||
// grab issues from github in batches of 100
|
||||
async getIssues(page: number): Promise<Issue[]> {
|
||||
// generate type for response
|
||||
const endpoint = this.client.issues.listForRepo;
|
||||
type OctoKitIssueList = GetResponseTypeFromEndpointMethod<typeof endpoint>;
|
||||
|
||||
try {
|
||||
this.operations.consumeOperation();
|
||||
const issueResult: OctoKitIssueList =
|
||||
await this.client.issues.listForRepo({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
state: 'open',
|
||||
per_page: 100,
|
||||
direction: this.options.ascending ? 'asc' : 'desc',
|
||||
page
|
||||
});
|
||||
const issueResult = await this.client.rest.issues.listForRepo({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
state: 'open',
|
||||
per_page: 100,
|
||||
direction: this.options.ascending ? 'asc' : 'desc',
|
||||
page
|
||||
});
|
||||
this.statistics?.incrementFetchedItemsCount(issueResult.data.length);
|
||||
|
||||
return issueResult.data.map(
|
||||
(issue: Readonly<IIssue>): Issue => new Issue(this.options, issue)
|
||||
(issue: Readonly<OctokitIssue>): Issue => new Issue(this.options, issue)
|
||||
);
|
||||
} catch (error) {
|
||||
this._logger.error(`Get issues for repo error: ${error.message}`);
|
||||
|
@ -570,7 +565,7 @@ export class IssuesProcessor {
|
|||
|
||||
this._consumeIssueOperation(issue);
|
||||
this.statistics?.incrementFetchedItemsEventsCount();
|
||||
const options = this.client.issues.listEvents.endpoint.merge({
|
||||
const options = this.client.rest.issues.listEvents.endpoint.merge({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
per_page: 100,
|
||||
|
@ -601,7 +596,7 @@ export class IssuesProcessor {
|
|||
this._consumeIssueOperation(issue);
|
||||
this.statistics?.incrementFetchedPullRequestsCount();
|
||||
|
||||
const pullRequest = await this.client.pulls.get({
|
||||
const pullRequest = await this.client.rest.pulls.get({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
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?
|
||||
if (shouldRemoveStaleWhenUpdated && issueHasComments) {
|
||||
if (
|
||||
shouldRemoveStaleWhenUpdated &&
|
||||
issueHasComments &&
|
||||
!issue.markedStaleThisRun
|
||||
) {
|
||||
issueLogger.info(
|
||||
`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
|
||||
const comments = await this.listIssueComments(issue.number, sinceDate);
|
||||
const comments = await this.listIssueComments(issue, sinceDate);
|
||||
|
||||
const filteredComments = comments.filter(
|
||||
comment =>
|
||||
comment.user.type === 'User' &&
|
||||
comment.body.toLowerCase() !== staleMessage.toLowerCase()
|
||||
comment.user?.type === 'User' &&
|
||||
comment.body?.toLowerCase() !== staleMessage.toLowerCase()
|
||||
);
|
||||
|
||||
issueLogger.info(
|
||||
|
@ -775,7 +778,7 @@ export class IssuesProcessor {
|
|||
this.statistics?.incrementAddedItemsComment(issue);
|
||||
|
||||
if (!this.options.debugOnly) {
|
||||
await this.client.issues.createComment({
|
||||
await this.client.rest.issues.createComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: issue.number,
|
||||
|
@ -793,7 +796,7 @@ export class IssuesProcessor {
|
|||
this.statistics?.incrementStaleItemsCount(issue);
|
||||
|
||||
if (!this.options.debugOnly) {
|
||||
await this.client.issues.addLabels({
|
||||
await this.client.rest.issues.addLabels({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: issue.number,
|
||||
|
@ -823,7 +826,7 @@ export class IssuesProcessor {
|
|||
this.addedCloseCommentIssues.push(issue);
|
||||
|
||||
if (!this.options.debugOnly) {
|
||||
await this.client.issues.createComment({
|
||||
await this.client.rest.issues.createComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: issue.number,
|
||||
|
@ -841,7 +844,7 @@ export class IssuesProcessor {
|
|||
this.statistics?.incrementAddedItemsLabel(issue);
|
||||
|
||||
if (!this.options.debugOnly) {
|
||||
await this.client.issues.addLabels({
|
||||
await this.client.rest.issues.addLabels({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: issue.number,
|
||||
|
@ -858,7 +861,7 @@ export class IssuesProcessor {
|
|||
this.statistics?.incrementClosedItemsCount(issue);
|
||||
|
||||
if (!this.options.debugOnly) {
|
||||
await this.client.issues.update({
|
||||
await this.client.rest.issues.update({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: issue.number,
|
||||
|
@ -900,7 +903,7 @@ export class IssuesProcessor {
|
|||
this.statistics?.incrementDeletedBranchesCount();
|
||||
|
||||
if (!this.options.debugOnly) {
|
||||
await this.client.git.deleteRef({
|
||||
await this.client.rest.git.deleteRef({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
ref: `heads/${branch}`
|
||||
|
@ -935,7 +938,7 @@ export class IssuesProcessor {
|
|||
this.statistics?.incrementDeletedItemsLabelsCount(issue);
|
||||
|
||||
if (!this.options.debugOnly) {
|
||||
await this.client.issues.removeLabel({
|
||||
await this.client.rest.issues.removeLabel({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: issue.number,
|
||||
|
@ -1065,10 +1068,10 @@ export class IssuesProcessor {
|
|||
this.addedLabelIssues.push(issue);
|
||||
|
||||
try {
|
||||
this.operations.consumeOperation();
|
||||
this._consumeIssueOperation(issue);
|
||||
this.statistics?.incrementAddedItemsLabel(issue);
|
||||
if (!this.options.debugOnly) {
|
||||
await this.client.issues.addLabels({
|
||||
await this.client.rest.issues.addLabels({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: issue.number,
|
||||
|
|
|
@ -9,6 +9,6 @@ import {CleanLabel} from '../types/clean-label';
|
|||
*
|
||||
* @return {string} A lowercased, deburred version of the passed in label
|
||||
*/
|
||||
export function cleanLabel(label: Readonly<string>): CleanLabel {
|
||||
return deburr(label.toLowerCase());
|
||||
export function cleanLabel(label?: Readonly<string>): CleanLabel {
|
||||
return deburr(label?.toLowerCase());
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import {IUser} from './user';
|
||||
|
||||
export interface IComment {
|
||||
user: IUser;
|
||||
body: string;
|
||||
user: IUser | null;
|
||||
body?: string;
|
||||
}
|
||||
|
|
|
@ -2,16 +2,18 @@ import {IsoDateString} from '../types/iso-date-string';
|
|||
import {Assignee} from './assignee';
|
||||
import {ILabel} from './label';
|
||||
import {IMilestone} from './milestone';
|
||||
|
||||
import {components} from '@octokit/openapi-types';
|
||||
export interface IIssue {
|
||||
title: string;
|
||||
number: number;
|
||||
created_at: IsoDateString;
|
||||
updated_at: IsoDateString;
|
||||
labels: ILabel[];
|
||||
pull_request: Object | null | undefined;
|
||||
pull_request?: Object | null;
|
||||
state: string;
|
||||
locked: boolean;
|
||||
milestone: IMilestone | undefined;
|
||||
assignees: Assignee[];
|
||||
milestone?: IMilestone | null;
|
||||
assignees?: Assignee[] | null;
|
||||
}
|
||||
|
||||
export type OctokitIssue = components['schemas']['issue'];
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
export interface ILabel {
|
||||
name: string;
|
||||
name?: string;
|
||||
}
|
||||
|
|
|
@ -3,5 +3,5 @@ export interface IPullRequest {
|
|||
head: {
|
||||
ref: string;
|
||||
};
|
||||
draft: boolean;
|
||||
draft?: boolean;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue