-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from soichisumi/add-test
Add test
- Loading branch information
Showing
6 changed files
with
78 additions
and
92 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
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
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const github = require('@actions/github'); | ||
|
||
const getIssueNumber = () => { | ||
const issue = github.context.payload.issue; | ||
if (!issue) { | ||
throw new Error("No issue provided"); | ||
} | ||
return issue.number; | ||
}; | ||
module.exports.getIssueNumber = getIssueNumber; | ||
|
||
// getIssue from context | ||
const getIssue = async (token) => { | ||
let octocat = new github.GitHub(token); | ||
const issueNum = getIssueNumber(); | ||
|
||
const repo = github.context.repo; | ||
const issue = await octocat.issues.get({ | ||
owner: repo.owner, | ||
repo: repo.repo, | ||
issue_number: issueNum, | ||
}); | ||
|
||
return issue; | ||
}; | ||
module.exports.getIssue = getIssue; | ||
|
||
const checkKeywords = (keywords, body) => { | ||
const lowerBody = body.toLowerCase(); | ||
for(let k of keywords) { | ||
if (lowerBody.toLowerCase().includes(k.toLowerCase())){ | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
module.exports.checkKeywords = checkKeywords; | ||
|
||
const createNewIssue = async (token, owner, repoName, title, body, assignees, labels, fromIssue) => { | ||
const octokit = new github.GitHub(token); | ||
if (fromIssue) { | ||
body = body + `\n\ncopiedFrom: ${fromIssue}`; | ||
} | ||
|
||
const res = await octokit.issues.create( | ||
{ | ||
owner: owner, | ||
repo: repoName, | ||
title: title, | ||
body: body, | ||
assignees: assignees, | ||
labels: labels, | ||
} | ||
); | ||
return [res.id, res.number].join(':'); | ||
}; | ||
module.exports.createNewIssue = createNewIssue; |
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,14 @@ | ||
const lib = require('./lib'); | ||
|
||
|
||
describe('checkKeyword', () => { | ||
it('return true if any keyword is found in given string', () => { | ||
expect(lib.checkKeywords(['/copy'], 'body of issue_comment. /copy')).toBe(true); | ||
}); | ||
it('return false if any keyword is not found', ()=> { | ||
expect(lib.checkKeywords(['/copy'], 'body of issue_comment.')).toBe(false); | ||
}); | ||
it('multiple keyword', () => { | ||
expect(lib.checkKeywords(['/copy', 'COPY'], 'body of issue_comment. copy')).toBe(true); | ||
}); | ||
}); |
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