-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Support Workflows Triggered By "Push" Event (#24)
Adds support for workflows triggered by a "push" event. This is necessary when integrating with tools that scan on pushes to the default branch, because it allows this action to be appended at the end of the workflow, to share the results of the scan with Pixeebot. /closes #work
- Loading branch information
Showing
2 changed files
with
104 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
const fakeContext = { | ||
sha: "workflow-sha", | ||
repo: { | ||
owner: "owner", | ||
repo: "repo", | ||
}, | ||
}; | ||
describe("github", () => { | ||
beforeEach(() => { | ||
jest.resetModules(); | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it("creates GitHubContext from push event", () => { | ||
jest.doMock("@actions/github", () => ({ | ||
context: { | ||
...fakeContext, | ||
eventName: "push", | ||
}, | ||
})); | ||
const github = require("../src/github"); | ||
|
||
const result = github.getGitHubContext(); | ||
expect(result).toEqual({ | ||
owner: "owner", | ||
repo: "repo", | ||
sha: "workflow-sha", | ||
}); | ||
}); | ||
|
||
it("creates GitHubContext from pull_request event", () => { | ||
jest.doMock("@actions/github", () => ({ | ||
context: { | ||
...fakeContext, | ||
eventName: "pull_request", | ||
issue: { number: 42 }, | ||
payload: { | ||
pull_request: { | ||
head: { sha: "pr-sha" }, | ||
}, | ||
}, | ||
}, | ||
})); | ||
const github = require("../src/github"); | ||
|
||
const result = github.getGitHubContext(); | ||
expect(result).toEqual({ | ||
owner: "owner", | ||
repo: "repo", | ||
sha: "pr-sha", | ||
prNumber: 42, | ||
}); | ||
}); | ||
|
||
it("creates GitHubContext from check_run event", () => { | ||
jest.doMock("@actions/github", () => ({ | ||
context: { | ||
...fakeContext, | ||
eventName: "check_run", | ||
payload: { | ||
check_run: { | ||
pull_requests: [{ number: 42 }], | ||
head_sha: "check-run-sha", | ||
}, | ||
}, | ||
}, | ||
})); | ||
const github = require("../src/github"); | ||
|
||
const result = github.getGitHubContext(); | ||
expect(result).toEqual({ | ||
owner: "owner", | ||
repo: "repo", | ||
sha: "check-run-sha", | ||
prNumber: 42, | ||
}); | ||
}); | ||
|
||
it("throws an error for unsupported event", () => { | ||
jest.doMock("@actions/github", () => ({ | ||
context: { | ||
...fakeContext, | ||
eventName: "unsupported", | ||
}, | ||
})); | ||
const github = require("../src/github"); | ||
|
||
expect(() => github.getGitHubContext()).toThrow( | ||
"Unsupported event: unsupported", | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters