-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: rewrite action and add new commands (#245)
* refactor: update function params * test pr to fix release action * refactor: update comment class to support other cmds * still refactoring... * added a few commands, next -> fix tests * ignore tests for now * refactor cmds and add debug logs * debugging... * hum, weird * debugging /assign cmd * oh boy * testing action output * return after setting output * testing yaml arrays and comment suggestion * revert maintainers array input * move common texts to an array * ship it
- Loading branch information
1 parent
54dd171
commit cc6c349
Showing
51 changed files
with
43,997 additions
and
24,685 deletions.
There are no files selected for viewing
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
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
Empty file.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -14,4 +14,5 @@ coverage/ | |
.dccache | ||
|
||
TODO.md | ||
.env | ||
.env | ||
test.json |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
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,170 @@ | ||
import * as core from '@actions/core'; | ||
import * as github from '@actions/github'; | ||
|
||
import CommentHandler from '../src/handlers/comment-handler'; | ||
import { getDefaultValues } from '../src/utils/helpers/default-values'; | ||
|
||
jest.mock('@actions/core'); | ||
jest.mock('@actions/github'); | ||
|
||
// function calculateDaysUntilUnassign(createAt: string, totalDays: number) { | ||
// const createdAt = new Date(createAt); | ||
// const currentDate = new Date(); | ||
// const diffTime = Math.abs(currentDate.getTime() - createdAt.getTime()); | ||
// const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); | ||
|
||
// return totalDays - diffDays; | ||
// } | ||
|
||
describe('Comment Handler', () => { | ||
// let client: ReturnType<typeof github.getOctokit>; | ||
let cmtHandler: CommentHandler; | ||
|
||
beforeAll(() => { | ||
jest.spyOn(core, 'getInput').mockImplementation((name, options) => { | ||
return jest.requireActual('@actions/core').getInput(name, options); | ||
}); | ||
jest.spyOn(core, 'setFailed').mockImplementation((message) => { | ||
return jest.requireActual('@actions/core').setFailed(message); | ||
}); | ||
jest.spyOn(core, 'info').mockImplementation((message) => { | ||
return jest.requireActual('@actions/core').info(message); | ||
}); | ||
|
||
// client = github.getOctokit('_'); | ||
cmtHandler = new CommentHandler(); | ||
|
||
Object.assign(process.env, getDefaultValues()); | ||
}); | ||
|
||
beforeEach(() => { | ||
process.env.INPUT_GITHUB_TOKEN = 'token'; | ||
process.env.INPUT_REQUIRED_LABEL = ''; | ||
github.context.payload.comment!.body = | ||
"Hey, I'm interested in this issue. Can you /assign-me please?"; | ||
}); | ||
|
||
afterAll(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
it('should exit early if token is not provided', async () => { | ||
process.env.INPUT_GITHUB_TOKEN = ''; | ||
await cmtHandler.handle_issue_comment(); | ||
expect(core.setFailed).toHaveBeenCalled(); | ||
expect(core.setFailed).toHaveBeenCalledWith( | ||
`🚫 Missing required input "token", received "${process.env.INPUT_GITHUB_TOKEN}"`, | ||
); | ||
}); | ||
|
||
// it('should ignore the comment if it does not contain the trigger', async () => { | ||
// github.context.payload.comment!.body = 'Hey, can you assign this to me?'; | ||
// await commentHandler.handleAssignIssue(); | ||
// expect(core.info).toHaveBeenCalled(); | ||
// expect(core.info).toHaveBeenCalledWith( | ||
// `🤖 Ignoring comment: ${github.context.payload.comment?.body}`, | ||
// ); | ||
// }); | ||
|
||
// it('should failed if required_label is provided but not in the issue', async () => { | ||
// commentHandler = new Comment(); | ||
// process.env.INPUT_REQUIRED_LABEL = 'Required'; | ||
// await commentHandler.handleAssignIssue(); | ||
// expect(core.setFailed).toHaveBeenCalled(); | ||
// expect(core.setFailed).toHaveBeenCalledWith( | ||
// `🚫 Missing required label: "[${process.env.INPUT_REQUIRED_LABEL}]" label not found in issue #${github.context.payload.issue?.number}.`, | ||
// ); | ||
// }); | ||
|
||
// it('should let the user know the issue is already assigned', async () => { | ||
// const commenter = github.context.payload.comment!.user.login; | ||
// const assignee = github.context.payload.issue!.assignee!.login; | ||
// const daysUntilUnassign = calculateDaysUntilUnassign( | ||
// github.context.payload.issue!.created_at, | ||
// Number(process.env.INPUT_DAYS_UNTIL_UNASSIGN), | ||
// ); | ||
|
||
// await commentHandler.handleAssignIssue(); | ||
// expect(client.rest.issues.listComments).toHaveBeenCalled(); | ||
// expect(client.rest.issues.listComments).toHaveBeenCalledWith({ | ||
// owner: 'TAKANOME-DEV', | ||
// repo: 'test-action', | ||
// issue_number: 1, | ||
// }); | ||
// expect(client.rest.issues.createComment).toHaveBeenCalled(); | ||
// expect(client.rest.issues.createComment).toHaveBeenCalledWith({ | ||
// owner: 'TAKANOME-DEV', | ||
// repo: 'test-action', | ||
// issue_number: 1, | ||
// body: `👋 Hey @${commenter}, this issue is already assigned to @${assignee}. | ||
|
||
// ⚠️ It will become unassigned if it isn't closed within **${daysUntilUnassign} days**. | ||
|
||
// 🔧 A maintainer can also add you to the list of assignees or swap you with the current assignee.`, | ||
// }); | ||
// expect(core.info).toHaveBeenCalled(); | ||
// expect(core.info).toHaveBeenCalledWith( | ||
// `🤖 Issue #${github.context.payload.issue?.number} is already assigned to @${assignee}`, | ||
// ); | ||
// }); | ||
|
||
// it('assign the user if there is no assignee', async () => { | ||
// github.context.payload.issue!.assignee = null; | ||
// await commentHandler.handleAssignIssue(); | ||
|
||
// expect(core.info).toHaveBeenCalled(); | ||
// expect(core.info).toHaveBeenCalledWith( | ||
// `🤖 Assigning @${github.context.payload.comment?.user.login} to issue #${github.context.payload.issue?.number}`, | ||
// ); | ||
// expect(client.rest.issues.addAssignees).toHaveBeenCalled(); | ||
// expect(client.rest.issues.addAssignees).toHaveBeenCalledWith({ | ||
// owner: 'TAKANOME-DEV', | ||
// repo: 'test-action', | ||
// issue_number: 1, | ||
// assignees: ['john-doe'], | ||
// }); | ||
// }); | ||
|
||
// it('add "Assigned" label if user is assigned', async () => { | ||
// await commentHandler.handleAssignIssue(); | ||
|
||
// expect(core.info).toHaveBeenCalled(); | ||
// expect(core.info).toHaveBeenCalledWith( | ||
// `🤖 Assigning @${github.context.payload.comment?.user.login} to issue #${github.context.payload.issue?.number}`, | ||
// ); | ||
// expect(client.rest.issues.addLabels).toHaveBeenCalled(); | ||
// expect(client.rest.issues.addLabels).toHaveBeenCalledWith({ | ||
// owner: 'TAKANOME-DEV', | ||
// repo: 'test-action', | ||
// issue_number: 1, | ||
// labels: ['📍 Assigned'], | ||
// }); | ||
// }); | ||
|
||
// it('should create a comment', async () => { | ||
// const commenter = github.context.payload.comment!.user.login; | ||
// const totalDays = process.env.INPUT_DAYS_UNTIL_UNASSIGN; | ||
// const pinnedLabel = process.env.INPUT_PIN_LABEL; | ||
|
||
// await commentHandler.handleAssignIssue(); | ||
// expect(core.info).toHaveBeenCalled(); | ||
// expect(core.info).toHaveBeenCalledWith( | ||
// `🤖 Adding comment to issue #${github.context.payload.issue?.number}`, | ||
// ); | ||
// expect(client.rest.issues.createComment).toHaveBeenCalled(); | ||
// expect(client.rest.issues.createComment).toHaveBeenCalledWith({ | ||
// owner: 'TAKANOME-DEV', | ||
// repo: 'test-action', | ||
// issue_number: 1, | ||
// body: `👋 Hey @${commenter}, thanks for your interest in this issue! 🎉 | ||
|
||
// ⚠ Note that this issue will become unassigned if it isn't closed within **${totalDays} days**. | ||
|
||
// 🔧 A maintainer can also add the **${pinnedLabel}** label to prevent it from being unassigned automatically.`, | ||
// }); | ||
// expect(core.info).toHaveBeenCalled(); | ||
// expect(core.info).toHaveBeenCalledWith( | ||
// `🤖 Issue #${github.context.payload.issue?.number} assigned!`, | ||
// ); | ||
// }); | ||
}); |
Oops, something went wrong.