Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,24 @@ jobs:
exempt-all-pr-assignees: true
```

Close stale issues and PRs in different repository:

```yaml
name: 'Close stale issues and PRs'
on:
schedule:
- cron: '30 1 * * *'

jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v9
with:
repo-token: # A PAT that has a minimum of triage permissions on my-org/my-repo
repository: my-org/my-repo
```

### Debugging

**Logs:**
Expand Down
4 changes: 3 additions & 1 deletion __tests__/constants/default-processor-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,7 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
ignorePrUpdates: undefined,
exemptDraftPr: false,
closeIssueReason: 'not_planned',
includeOnlyAssigned: false
includeOnlyAssigned: false,
owner: 'dummy-owner',
repo: 'dummy-repo'
});
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ inputs:
description: 'Only the issues or the pull requests with an assignee will be marked as stale automatically.'
default: 'false'
required: false
repository:
description: 'Repository to process PRs from. Defaults to the current repository'
required: false
outputs:
closed-issues-prs:
description: 'List of all closed issues and pull requests.'
Expand Down
66 changes: 41 additions & 25 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,8 @@ class IssuesProcessor {
this._consumeIssueOperation(issue);
(_a = this.statistics) === null || _a === void 0 ? void 0 : _a.incrementFetchedItemsCommentsCount();
const comments = yield this.client.rest.issues.listComments({
owner: github_1.context.repo.owner,
repo: github_1.context.repo.repo,
owner: this.options.owner,
repo: this.options.repo,
issue_number: issue.number,
since: sinceDate
});
Expand All @@ -679,8 +679,8 @@ class IssuesProcessor {
try {
this.operations.consumeOperation();
const issueResult = yield this.client.rest.issues.listForRepo({
owner: github_1.context.repo.owner,
repo: github_1.context.repo.repo,
owner: this.options.owner,
repo: this.options.repo,
state: 'open',
per_page: 100,
direction: this.options.ascending ? 'asc' : 'desc',
Expand All @@ -704,8 +704,8 @@ class IssuesProcessor {
this._consumeIssueOperation(issue);
(_a = this.statistics) === null || _a === void 0 ? void 0 : _a.incrementFetchedItemsEventsCount();
const options = this.client.rest.issues.listEvents.endpoint.merge({
owner: github_1.context.repo.owner,
repo: github_1.context.repo.repo,
owner: this.options.owner,
repo: this.options.repo,
per_page: 100,
issue_number: issue.number
});
Expand All @@ -728,8 +728,8 @@ class IssuesProcessor {
this._consumeIssueOperation(issue);
(_a = this.statistics) === null || _a === void 0 ? void 0 : _a.incrementFetchedPullRequestsCount();
const pullRequest = yield this.client.rest.pulls.get({
owner: github_1.context.repo.owner,
repo: github_1.context.repo.repo,
owner: this.options.owner,
repo: this.options.repo,
pull_number: issue.number
});
return pullRequest.data;
Expand Down Expand Up @@ -848,8 +848,8 @@ class IssuesProcessor {
(_a = this.statistics) === null || _a === void 0 ? void 0 : _a.incrementAddedItemsComment(issue);
if (!this.options.debugOnly) {
yield this.client.rest.issues.createComment({
owner: github_1.context.repo.owner,
repo: github_1.context.repo.repo,
owner: this.options.owner,
repo: this.options.repo,
issue_number: issue.number,
body: staleMessage
});
Expand All @@ -865,8 +865,8 @@ class IssuesProcessor {
(_c = this.statistics) === null || _c === void 0 ? void 0 : _c.incrementStaleItemsCount(issue);
if (!this.options.debugOnly) {
yield this.client.rest.issues.addLabels({
owner: github_1.context.repo.owner,
repo: github_1.context.repo.repo,
owner: this.options.owner,
repo: this.options.repo,
issue_number: issue.number,
labels: [staleLabel]
});
Expand All @@ -891,8 +891,8 @@ class IssuesProcessor {
this.addedCloseCommentIssues.push(issue);
if (!this.options.debugOnly) {
yield this.client.rest.issues.createComment({
owner: github_1.context.repo.owner,
repo: github_1.context.repo.repo,
owner: this.options.owner,
repo: this.options.repo,
issue_number: issue.number,
body: closeMessage
});
Expand All @@ -908,8 +908,8 @@ class IssuesProcessor {
(_b = this.statistics) === null || _b === void 0 ? void 0 : _b.incrementAddedItemsLabel(issue);
if (!this.options.debugOnly) {
yield this.client.rest.issues.addLabels({
owner: github_1.context.repo.owner,
repo: github_1.context.repo.repo,
owner: this.options.owner,
repo: this.options.repo,
issue_number: issue.number,
labels: [closeLabel]
});
Expand All @@ -924,8 +924,8 @@ class IssuesProcessor {
(_c = this.statistics) === null || _c === void 0 ? void 0 : _c.incrementClosedItemsCount(issue);
if (!this.options.debugOnly) {
yield this.client.rest.issues.update({
owner: github_1.context.repo.owner,
repo: github_1.context.repo.repo,
owner: this.options.owner,
repo: this.options.repo,
issue_number: issue.number,
state: 'closed',
state_reason: this.options.closeIssueReason || undefined
Expand Down Expand Up @@ -955,15 +955,15 @@ class IssuesProcessor {
const branch = pullRequest.head.ref;
if (pullRequest.head.repo === null ||
pullRequest.head.repo.full_name ===
`${github_1.context.repo.owner}/${github_1.context.repo.repo}`) {
`${this.options.owner}/${this.options.repo}`) {
issueLogger.info(`Deleting the branch "${logger_service_1.LoggerService.cyan(branch)}" from closed $$type`);
try {
this._consumeIssueOperation(issue);
(_a = this.statistics) === null || _a === void 0 ? void 0 : _a.incrementDeletedBranchesCount();
if (!this.options.debugOnly) {
yield this.client.rest.git.deleteRef({
owner: github_1.context.repo.owner,
repo: github_1.context.repo.repo,
owner: this.options.owner,
repo: this.options.repo,
ref: `heads/${branch}`
});
}
Expand All @@ -989,8 +989,8 @@ class IssuesProcessor {
(_a = this.statistics) === null || _a === void 0 ? void 0 : _a.incrementDeletedItemsLabelsCount(issue);
if (!this.options.debugOnly) {
yield this.client.rest.issues.removeLabel({
owner: github_1.context.repo.owner,
repo: github_1.context.repo.repo,
owner: this.options.owner,
repo: this.options.repo,
issue_number: issue.number,
name: label
});
Expand Down Expand Up @@ -1089,8 +1089,8 @@ class IssuesProcessor {
(_a = this.statistics) === null || _a === void 0 ? void 0 : _a.incrementAddedItemsLabel(issue);
if (!this.options.debugOnly) {
yield this.client.rest.issues.addLabels({
owner: github_1.context.repo.owner,
repo: github_1.context.repo.repo,
owner: this.options.owner,
repo: this.options.repo,
issue_number: issue.number,
labels: labelsToAdd
});
Expand Down Expand Up @@ -2483,6 +2483,7 @@ const core = __importStar(__nccwpck_require__(2186));
const issues_processor_1 = __nccwpck_require__(3292);
const is_valid_date_1 = __nccwpck_require__(891);
const state_service_1 = __nccwpck_require__(6330);
const github_1 = __nccwpck_require__(5438);
function _run() {
return __awaiter(this, void 0, void 0, function* () {
try {
Expand Down Expand Up @@ -2512,7 +2513,10 @@ function _run() {
});
}
function _getAndValidateArgs() {
const { owner, repo } = getOwnerRepo();
const args = {
owner,
repo,
repoToken: core.getInput('repo-token'),
staleIssueMessage: core.getInput('stale-issue-message'),
stalePrMessage: core.getInput('stale-pr-message'),
Expand Down Expand Up @@ -2628,6 +2632,18 @@ function _toOptionalBoolean(argumentName) {
}
return undefined;
}
function getOwnerRepo() {
let { owner, repo } = github_1.context.repo;
const repository = core.getInput('repository');
if (repository) {
const components = repository.split('/');
if (components.length !== 2) {
throw new Error(`Invalid repository format "${repository}". Expected "owner/repo".`);
}
[owner, repo] = components;
}
return { owner, repo };
}
void _run();


Expand Down
4 changes: 3 additions & 1 deletion src/classes/issue.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ describe('Issue', (): void => {
ignorePrUpdates: undefined,
exemptDraftPr: false,
closeIssueReason: '',
includeOnlyAssigned: false
includeOnlyAssigned: false,
owner: 'dummy-owner',
repo: 'dummy-repo'
};
issueInterface = {
title: 'dummy-title',
Expand Down
52 changes: 26 additions & 26 deletions src/classes/issues-processor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as core from '@actions/core';
import {context, getOctokit} from '@actions/github';
import {getOctokit} from '@actions/github';
import {GitHub} from '@actions/github/lib/utils';
import {Option} from '../enums/option';
import {getHumanizedDate} from '../functions/dates/get-humanized-date';
Expand Down Expand Up @@ -549,8 +549,8 @@ export class IssuesProcessor {
this._consumeIssueOperation(issue);
this.statistics?.incrementFetchedItemsCommentsCount();
const comments = await this.client.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
owner: this.options.owner,
repo: this.options.repo,
issue_number: issue.number,
since: sinceDate
});
Expand All @@ -566,8 +566,8 @@ export class IssuesProcessor {
try {
this.operations.consumeOperation();
const issueResult = await this.client.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
owner: this.options.owner,
repo: this.options.repo,
state: 'open',
per_page: 100,
direction: this.options.ascending ? 'asc' : 'desc',
Expand Down Expand Up @@ -597,8 +597,8 @@ export class IssuesProcessor {
this._consumeIssueOperation(issue);
this.statistics?.incrementFetchedItemsEventsCount();
const options = this.client.rest.issues.listEvents.endpoint.merge({
owner: context.repo.owner,
repo: context.repo.repo,
owner: this.options.owner,
repo: this.options.repo,
per_page: 100,
issue_number: issue.number
});
Expand Down Expand Up @@ -628,8 +628,8 @@ export class IssuesProcessor {
this.statistics?.incrementFetchedPullRequestsCount();

const pullRequest = await this.client.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
owner: this.options.owner,
repo: this.options.repo,
pull_number: issue.number
});

Expand Down Expand Up @@ -848,8 +848,8 @@ export class IssuesProcessor {

if (!this.options.debugOnly) {
await this.client.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
owner: this.options.owner,
repo: this.options.repo,
issue_number: issue.number,
body: staleMessage
});
Expand All @@ -866,8 +866,8 @@ export class IssuesProcessor {

if (!this.options.debugOnly) {
await this.client.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
owner: this.options.owner,
repo: this.options.repo,
issue_number: issue.number,
labels: [staleLabel]
});
Expand Down Expand Up @@ -896,8 +896,8 @@ export class IssuesProcessor {

if (!this.options.debugOnly) {
await this.client.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
owner: this.options.owner,
repo: this.options.repo,
issue_number: issue.number,
body: closeMessage
});
Expand All @@ -914,8 +914,8 @@ export class IssuesProcessor {

if (!this.options.debugOnly) {
await this.client.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
owner: this.options.owner,
repo: this.options.repo,
issue_number: issue.number,
labels: [closeLabel]
});
Expand All @@ -931,8 +931,8 @@ export class IssuesProcessor {

if (!this.options.debugOnly) {
await this.client.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
owner: this.options.owner,
repo: this.options.repo,
issue_number: issue.number,
state: 'closed',
state_reason: this.options.closeIssueReason || undefined
Expand Down Expand Up @@ -968,7 +968,7 @@ export class IssuesProcessor {
if (
pullRequest.head.repo === null ||
pullRequest.head.repo.full_name ===
`${context.repo.owner}/${context.repo.repo}`
`${this.options.owner}/${this.options.repo}`
) {
issueLogger.info(
`Deleting the branch "${LoggerService.cyan(branch)}" from closed $$type`
Expand All @@ -980,8 +980,8 @@ export class IssuesProcessor {

if (!this.options.debugOnly) {
await this.client.rest.git.deleteRef({
owner: context.repo.owner,
repo: context.repo.repo,
owner: this.options.owner,
repo: this.options.repo,
ref: `heads/${branch}`
});
}
Expand Down Expand Up @@ -1024,8 +1024,8 @@ export class IssuesProcessor {

if (!this.options.debugOnly) {
await this.client.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
owner: this.options.owner,
repo: this.options.repo,
issue_number: issue.number,
name: label
});
Expand Down Expand Up @@ -1162,8 +1162,8 @@ export class IssuesProcessor {
this.statistics?.incrementAddedItemsLabel(issue);
if (!this.options.debugOnly) {
await this.client.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
owner: this.options.owner,
repo: this.options.repo,
issue_number: issue.number,
labels: labelsToAdd
});
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/issues-processor-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@ export interface IIssuesProcessorOptions {
exemptDraftPr: boolean;
closeIssueReason: string;
includeOnlyAssigned: boolean;
owner: string;
repo: string;
}
Loading