Skip to content

Commit

Permalink
feat: Fetch config file internally without actions/checkout (#489)
Browse files Browse the repository at this point in the history
Close #447

- Fetch config file internally without actions/checkout
- Comment body placeholders:
	- Add `{{ owner }}` and `{{ repo }}`
	- Deprecate `{{ (issue|pull_request|discussion).user.login }}` and `{{ sender.login }}`
  • Loading branch information
peaceiris authored Sep 4, 2021
1 parent a7daa43 commit d5ef6e2
Show file tree
Hide file tree
Showing 12 changed files with 250 additions and 201 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/label-commenter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ jobs:
runs-on: ubuntu-20.04
timeout-minutes: 1
steps:
- uses: actions/[email protected]
with:
ref: main

- name: Label Commenter
uses: peaceiris/actions-label-commenter@70a7e5a7341326e42a96580b0134a4054c47e2a8
env:
Expand Down
55 changes: 32 additions & 23 deletions __tests__/classes/action-processor.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {getOctokit} from '@actions/github';

import {ActionProcessor} from '../../src/classes/action-processor';
import {IConfig} from '../../src/classes/config';
import {IConfig, Action, Draft} from '../../src/classes/config';
import {EventAlias} from '../../src/classes/context-loader';
import {Issue} from '../../src/classes/issue';

Expand All @@ -21,7 +21,7 @@ const issueMock: Issue = {
lockLockable: jest.fn(),
unlockLockable: jest.fn(),
markDiscussionCommentAsAnswer: jest.fn()
};
} as const;
const tests: Array<EventAlias> = ['issue', 'pr'];

// beforeAll(() => {
Expand All @@ -43,7 +43,7 @@ describe('Comment and close', () => {
locking: undefined,
lockReason: undefined,
answer: undefined
};
} as const;
const actionProcessor = new ActionProcessor(t, config, commentBody, issueMock, false);
await actionProcessor.process();
expect(issueMock.createComment).toBeCalledTimes(1);
Expand All @@ -67,7 +67,7 @@ describe('Comment, close, and lock without reason', () => {
locking: 'lock',
lockReason: undefined,
answer: undefined
};
} as const;
const actionProcessor = new ActionProcessor(t, config, commentBody, issueMock, false);
await actionProcessor.process();
expect(issueMock.createComment).toBeCalledTimes(1);
Expand All @@ -92,7 +92,7 @@ describe('Comment, close, and lock with lockReason', () => {
locking: 'lock',
lockReason: 'spam',
answer: undefined
};
} as const;
const actionProcessor = new ActionProcessor(t, config, commentBody, issueMock, false);
await actionProcessor.process();
expect(issueMock.createComment).toBeCalledTimes(1);
Expand All @@ -117,7 +117,7 @@ describe('Unlock, open and comment', () => {
locking: 'unlock',
lockReason: undefined,
answer: undefined
};
} as const;
const actionProcessor = new ActionProcessor(t, config, commentBody, issueMock, true);
await actionProcessor.process();
expect(issueMock.unlock).toBeCalledTimes(1);
Expand All @@ -142,7 +142,7 @@ describe('Comment and open', () => {
locking: undefined,
lockReason: undefined,
answer: undefined
};
} as const;
const actionProcessor = new ActionProcessor(t, config, commentBody, issueMock, false);
await actionProcessor.process();
expect(issueMock.createComment).toBeCalledTimes(1);
Expand All @@ -166,7 +166,7 @@ describe('Open without comment if the issue is locked', () => {
locking: undefined,
lockReason: undefined,
answer: undefined
};
} as const;
const issueMock: Issue = {
githubClient: githubClient,
id: 'MDExOlB1bGxSZXF1ZXN0NzA2MTE5NTg0',
Expand All @@ -181,7 +181,7 @@ describe('Open without comment if the issue is locked', () => {
lockLockable: jest.fn(),
unlockLockable: jest.fn(),
markDiscussionCommentAsAnswer: jest.fn()
};
} as const;
const actionProcessor = new ActionProcessor(t, config, commentBody, issueMock, true);
await actionProcessor.process();
expect(issueMock.createComment).toBeCalledTimes(0);
Expand All @@ -204,7 +204,7 @@ describe('Skip all actions for a label that has no configuration', () => {
locking: undefined,
lockReason: undefined,
answer: undefined
};
} as const;
const actionProcessor = new ActionProcessor(t, config, commentBody, issueMock, false);
await actionProcessor.process();
expect(issueMock.createComment).toBeCalledTimes(0);
Expand Down Expand Up @@ -232,7 +232,7 @@ describe('Skip comment if body is empty', () => {
locking: 'lock',
lockReason: 'spam',
answer: undefined
};
} as const;
const commentBody = '';
const actionProcessor = new ActionProcessor(t, config, commentBody, issueMock, false);
await actionProcessor.process();
Expand All @@ -247,28 +247,37 @@ describe('Skip comment if body is empty', () => {
});

describe('Toggle draft status', () => {
const tests = [true, false];
const tests = [
{
action: 'open',
draft: true
},
{
action: 'close',
draft: false
}
];

for (const t of tests) {
test(`draft ${t}`, async () => {
const config: IConfig = {
config: {},
parentFieldName: `labels.invalid.labeled.pr`,
labelIndex: '0',
action: undefined,
action: t.action as Action,
locking: undefined,
lockReason: undefined,
draft: t,
draft: t.draft as Draft,
answer: undefined
};
} as const;
const actionProcessor = new ActionProcessor('pr', config, commentBody, issueMock, false);
await actionProcessor.process();
expect(issueMock.createComment).toBeCalledTimes(1);
expect(issueMock.updateState).toBeCalledTimes(0);
expect(issueMock.updateState).toBeCalledTimes(1);
expect(issueMock.lock).toBeCalledTimes(0);
expect(issueMock.unlock).toBeCalledTimes(0);
expect(issueMock.markPullRequestReadyForReview).toBeCalledTimes(t ? 0 : 1);
expect(issueMock.convertPullRequestToDraft).toBeCalledTimes(t ? 1 : 0);
expect(issueMock.markPullRequestReadyForReview).toBeCalledTimes(t.draft ? 0 : 1);
expect(issueMock.convertPullRequestToDraft).toBeCalledTimes(t.draft ? 1 : 0);
});
}
});
Expand All @@ -285,7 +294,7 @@ describe('discussion', () => {
locking: undefined,
lockReason: undefined,
answer: undefined
};
} as const;
const actionProcessor = new ActionProcessor(t, config, commentBody, issueMock, false);
await actionProcessor.process();
expect(issueMock.addDiscussionComment).toBeCalledTimes(1);
Expand All @@ -304,7 +313,7 @@ describe('discussion', () => {
locking: 'lock',
lockReason: 'spam',
answer: undefined
};
} as const;
const actionProcessor = new ActionProcessor(t, config, commentBody, issueMock, false);
await actionProcessor.process();
expect(issueMock.addDiscussionComment).toBeCalledTimes(1);
Expand All @@ -324,7 +333,7 @@ describe('discussion', () => {
locking: 'lock',
lockReason: undefined,
answer: undefined
};
} as const;
const actionProcessor = new ActionProcessor(t, config, commentBody, issueMock, false);
await actionProcessor.process();
expect(issueMock.addDiscussionComment).toBeCalledTimes(1);
Expand All @@ -344,7 +353,7 @@ describe('discussion', () => {
locking: 'unlock',
lockReason: undefined,
answer: undefined
};
} as const;
const actionProcessor = new ActionProcessor(t, config, commentBody, issueMock, true);
await actionProcessor.process();
expect(issueMock.addDiscussionComment).toBeCalledTimes(1);
Expand All @@ -363,7 +372,7 @@ describe('discussion', () => {
locking: undefined,
lockReason: undefined,
answer: true
};
} as const;
const actionProcessor = new ActionProcessor(t, config, commentBody, issueMock, false);
await actionProcessor.process();
expect(issueMock.addDiscussionComment).toBeCalledTimes(1);
Expand Down
Loading

0 comments on commit d5ef6e2

Please sign in to comment.