Skip to content

Commit

Permalink
feat: [+] gkampitakis#12 pull_request_target event
Browse files Browse the repository at this point in the history
  • Loading branch information
eruizalo committed Mar 7, 2023
1 parent 2f1c032 commit 2599e23
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/action-parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function getActionParameters(ctx: Context): GetActionParams {
const base = pull_request?.base?.ref;
const head = pull_request?.head?.ref;

if (eventName !== 'pull_request') {
if (eventName !== 'pull_request' && eventName !== 'pull_request_target') {
throw new Error('Action only supports pull requests');
}

Expand Down
22 changes: 22 additions & 0 deletions tests/__snapshots__/action-paramaters.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@ Object {
}
`;

exports[`getActionParameters should return action parameters on PR 1`] = `
Object {
"actor": "mock-actor",
"base": "master",
"head": "pr",
"owner": "mock-owner",
"prNumber": 10,
"repo": "mock-repo",
}
`;

exports[`getActionParameters should return action parameters on PRT 1`] = `
Object {
"actor": "mock-actor",
"base": "master",
"head": "pr",
"owner": "mock-owner",
"prNumber": 10,
"repo": "mock-repo",
}
`;

exports[`getInputs should return all inputs 1`] = `
Object {
"commentTitle": "my title",
Expand Down
21 changes: 20 additions & 1 deletion tests/action-paramaters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jest.mock('@actions/core', () => ({
}));

describe('getActionParameters', () => {
it('should return action parameters', () => {
it('should return action parameters on PR', () => {
const ctx = {
actor: 'mock-actor',
repo: {
Expand All @@ -27,6 +27,25 @@ describe('getActionParameters', () => {

expect(getActionParameters(ctx)).toMatchSnapshot();
});
it('should return action parameters on PRT', () => {
const ctx = {
actor: 'mock-actor',
repo: {
owner: 'mock-owner',
repo: 'mock-repo'
},
eventName: 'pull_request_target',
payload: {
pull_request: {
number: 10,
base: { ref: 'master' },
head: { ref: 'pr' }
}
}
} as unknown as Context;

expect(getActionParameters(ctx)).toMatchSnapshot();
});

it("should throw error if event != 'pull_request'", () => {
const ctx = {
Expand Down

0 comments on commit 2599e23

Please sign in to comment.