-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
287 additions
and
160 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 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,53 @@ | ||
module.exports = async ({title, body, sections}, summaryLink, context, github) => { | ||
// get comments | ||
const {data: comments} = await github.rest.issues.listComments({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo | ||
}); | ||
// prepare body | ||
let commentBody = '' | ||
if(title) { | ||
commentBody = `## ${title}\n\n` | ||
} | ||
if (body) { | ||
commentBody += body | ||
} | ||
if (sections) { | ||
commentBody += sections.map(({title, body}) => | ||
'<details>' + | ||
`<summary><h3>${title}</h3></summary>\n` + | ||
" \n"+ | ||
" ```diff"+ | ||
` ${body}` + | ||
" ```"+ | ||
'\n</details>' | ||
).join('\n') | ||
} | ||
|
||
// overwrite body if to long | ||
if(summaryLink && commentBody.length > 65536) { | ||
commentBody = `## ${title}\n\nThe message is too long to be displayed here. For more details, please check the <a href="${summaryLink}">job summary</a>.` | ||
} | ||
|
||
// get comment if exists | ||
const existingComment = comments.filter(comment => comment.body.includes(`## ${title}`)); | ||
// if comment exists, update it | ||
if(existingComment.length > 0) { | ||
await github.rest.issues.updateComment({ | ||
comment_id: existingComment[0].id, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: commentBody | ||
}) | ||
} | ||
// if comment does not exist, create it | ||
else { | ||
await github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: commentBody | ||
}) | ||
} | ||
} |
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,31 @@ | ||
const core = require('@actions/core') | ||
|
||
module.exports = (content, overwrite = false) => { | ||
if(!Array.isArray(content)) { | ||
content = [content] | ||
} | ||
// core.summary.clear() | ||
|
||
for (const {title, body, sections} of content) { | ||
if(title) { | ||
core.summary.addHeading(title, '1') | ||
} | ||
|
||
if(body) { | ||
core.summary.addRaw(body, true) | ||
} | ||
|
||
if(sections) { | ||
sections.forEach(({title, body}) => { | ||
const section = `<details><summary><h3>${title}</h3></summary>\n\n`+ | ||
'```diff\n'+ | ||
`${body}\n`+ | ||
'```\n\n'+ | ||
'</details>' | ||
core.summary.addRaw(section, true) | ||
}) | ||
} | ||
} | ||
// write summary | ||
core.summary.write({overwrite}) | ||
} |
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,23 @@ | ||
module.exports = async (searchContent, context, github) => { | ||
if (!Array.isArray(searchContent)) { | ||
searchContent = [searchContent] | ||
} | ||
// get comments | ||
const {data: comments} = await github.rest.issues.listComments({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo | ||
}); | ||
|
||
// get comments that match search content | ||
const existingComment = comments.filter(comment => searchContent.some(searchValue => comment.body.includes(searchValue))); | ||
|
||
// if token issue exists, update it | ||
for (const comment of existingComment) { | ||
await github.rest.issues.deleteComment({ | ||
comment_id: comment.id, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
}) | ||
} | ||
} |
Oops, something went wrong.