-
Notifications
You must be signed in to change notification settings - Fork 0
feat: support workflow_dispatch for build description #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ec7e0c2
feat: fetch commit message via API for workflow_dispatch
rqbazan 9956429
ci: unblock check-dist and drop broken e2e test job
claude 69b778d
docs: tighten description input wording in README
rqbazan 8baad73
test: extract getCommitMessage and cover its three branches
claude 1884565
test: cover createBuild description fallback chain end-to-end
rqbazan d184116
refactor: inline getCommitMessage in action.js
rqbazan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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
This file contains hidden or 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,94 @@ | ||
| const core = require('@actions/core'); | ||
| const github = require('@actions/github'); | ||
|
|
||
| jest.mock('@actions/core'); | ||
| jest.mock('@actions/github', () => ({ | ||
| getOctokit: jest.fn(), | ||
| context: { | ||
| repo: { owner: 'nullplatform', repo: 'main-providers-api' }, | ||
| sha: '', | ||
| ref: '', | ||
| payload: {}, | ||
| }, | ||
| })); | ||
|
|
||
| const mockPost = jest.fn(); | ||
| jest.mock('./client', () => jest.fn(() => ({ post: mockPost }))); | ||
|
|
||
| const run = require('./action'); | ||
|
|
||
| const setInputs = (overrides = {}) => { | ||
| const defaults = { action: 'create', 'application-id': 'app-1' }; | ||
| const all = { ...defaults, ...overrides }; | ||
| core.getInput.mockImplementation((name) => all[name] || ''); | ||
| }; | ||
|
|
||
| describe('run (createBuild path)', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| mockPost.mockResolvedValue({ id: 1, status: 'in_progress', application_id: 'app-1' }); | ||
| github.context.sha = 'abc123'; | ||
| github.context.ref = 'refs/heads/main'; | ||
| github.context.payload = { repository: { html_url: 'https://github.com/foo/bar' } }; | ||
| setInputs(); | ||
| }); | ||
|
|
||
| test('uses head_commit.message when payload contains it (push event)', async () => { | ||
| github.context.payload.head_commit = { message: 'feat: from push' }; | ||
|
|
||
| await run(); | ||
|
|
||
| expect(github.getOctokit).not.toHaveBeenCalled(); | ||
| expect(mockPost).toHaveBeenCalledWith('build', expect.objectContaining({ | ||
| description: 'feat: from push', | ||
| })); | ||
| }); | ||
|
|
||
| test('fetches the commit message via the GitHub API when head_commit is absent', async () => { | ||
| setInputs({ 'github-token': 'ghs_x' }); | ||
| const getCommit = jest.fn().mockResolvedValue({ data: { message: 'feat: from API' } }); | ||
| github.getOctokit.mockReturnValue({ rest: { git: { getCommit } } }); | ||
|
|
||
| await run(); | ||
|
|
||
| expect(github.getOctokit).toHaveBeenCalledWith('ghs_x'); | ||
| expect(getCommit).toHaveBeenCalledWith(expect.objectContaining({ commit_sha: 'abc123' })); | ||
| expect(mockPost).toHaveBeenCalledWith('build', expect.objectContaining({ | ||
| description: 'feat: from API', | ||
| })); | ||
| }); | ||
|
|
||
| test('falls back to "Commit <sha>" when github-token is empty and head_commit is absent', async () => { | ||
| await run(); | ||
|
|
||
| expect(github.getOctokit).not.toHaveBeenCalled(); | ||
| expect(mockPost).toHaveBeenCalledWith('build', expect.objectContaining({ | ||
| description: 'Commit abc123', | ||
| })); | ||
| }); | ||
|
|
||
| test('warns and falls back to "Commit <sha>" when the API call fails', async () => { | ||
| setInputs({ 'github-token': 'ghs_x' }); | ||
| const getCommit = jest.fn().mockRejectedValue(new Error('forbidden')); | ||
| github.getOctokit.mockReturnValue({ rest: { git: { getCommit } } }); | ||
|
|
||
| await run(); | ||
|
|
||
| expect(core.warning).toHaveBeenCalledWith(expect.stringContaining('forbidden')); | ||
| expect(mockPost).toHaveBeenCalledWith('build', expect.objectContaining({ | ||
| description: 'Commit abc123', | ||
| })); | ||
| }); | ||
|
|
||
| test('prefers explicit description input over payload and API', async () => { | ||
| setInputs({ description: 'from input', 'github-token': 'ghs_x' }); | ||
| github.context.payload.head_commit = { message: 'feat: from push' }; | ||
|
|
||
| await run(); | ||
|
|
||
| expect(github.getOctokit).not.toHaveBeenCalled(); | ||
| expect(mockPost).toHaveBeenCalledWith('build', expect.objectContaining({ | ||
| description: 'from input', | ||
| })); | ||
| }); | ||
| }); |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leftover from when the repo was bootstrapped as a fork of
actions/javascript-actionin327daaf(2023-04-12): at that commitaction.ymldeclared amillisecondsinput andindex.jswas the template'swaitcode, so the job passed.Six days later
b52f3e3("Build action") replaced the template with the Nullplatform action —millisecondswas gone — buttest.ymlwas never updated. Since then: emptyactioninput → noCREATE/UPDATEmatch →core.setFailed(...)withoutreturn→const { id, ... } = buildcrashes onnull.No merged PR since has seen it pass (older run logs were purged by retention, but this PR's
run_numberonunits-testwas#43and the only merge sinceb52f3e3is docs-only #19). Restoring it properly needs real credentials or a mock server — out of scope here;unitsalready runsnpm test.