Skip to content

Commit

Permalink
diff fallback config (#1097)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasoppermann authored Nov 28, 2024
1 parent fd8a353 commit 694b24e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 21 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/diff-design-tokens.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,25 @@ jobs:
with:
script: |
core.setOutput('diffs', `[{
"title": "## Design Token Diff (CSS)",
"title": "Design Token Diff (CSS)",
"folder": "dist/css",
"globString": "**/**/*.css",
"outputFile": "diff_css.json"
},{
"title": "## Design Token Diff (StyleLint)",
"title": "Design Token Diff (StyleLint)",
"folder": "dist/styleLint",
"globString": "**/**/*.json",
"outputFile": "diff_style_lint.json"
},{
"title": "## Design Token Diff (Figma)",
"title": "Design Token Diff (Figma)",
"folder": "dist/figma",
"globString": "**/**/*.json",
"outputFile": "diff_figma.json"
},{
"title": "Design Token Diff (Fallbacks)",
"folder": "dist/fallbacks",
"globString": "**/**/*.json",
"outputFile": "diff_fallbacks.json"
}]`)
diff:
Expand Down
56 changes: 40 additions & 16 deletions .github/workflows/utilities/addComment.cjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
const findCommentByContent = (searchContent, comments) => {
return comments.filter(comment => comment.body.includes(searchContent));
}

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
});
console.log(`Preparing comment content for ${title}`)
// prepare body
let commentBody = ''
if(title) {
Expand All @@ -30,24 +29,49 @@ module.exports = async ({title, body, sections}, summaryLink, context, github) =
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 comments
const {data: comments} = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
});

console.log(`Found ${comments.length} comments`)
// 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
})
const existingComment = findCommentByContent(`## ${title}`, comments);
console.log(`Found ${existingComment.length} comments, with the title "## ${title}"`)
// delete comment if no body or sections
if(!body && (!sections || sections.length === 0)) {
if(existingComment.length > 0 &&) {
console.log(`Deleting comment with the title "## ${title}" and the id ${existingComment[0].id}`)
// if comment exists, delete it
await github.rest.issues.deleteComment({
comment_id: existingComment[0].id,
owner: context.repo.owner,
repo: context.repo.repo,
})
}
return
}

// if comment does not exist, create it
else {
if(existingComment.length === 0) {
console.log(`Creating comment with the title "## ${title}"`)
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
})
return
}

// if comment exists, update it
console.log(`Updating comment with the title "## ${title}" and the id ${existingComment[0].id}`)
await github.rest.issues.updateComment({
comment_id: existingComment[0].id,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
})
}
9 changes: 7 additions & 2 deletions .github/workflows/utilities/addSummary.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ module.exports = (content, overwrite = false) => {
// core.summary.clear()

for (const {title, body, sections} of content) {
// if no body or sections, skip
if(!body && (!sections || sections.length === 0)) {
continue
}
// add heading
if(title) {
core.summary.addHeading(title, '1')
}

// add body
if(body) {
core.summary.addRaw(body, true)
}

// add sections
if(sections) {
sections.forEach(({title, body}) => {
const section = `<details><summary><h3>${title}</h3></summary>\n\n`+
Expand Down

0 comments on commit 694b24e

Please sign in to comment.