Skip to content

Commit

Permalink
feat: Add tweet preview to PR conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
IstoraMandiri committed Oct 5, 2022
1 parent 66e7a86 commit dd2ebac
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/pull-request/create-check-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ async function createCheckRun(
process.exit(allTweetsValid ? 0 : 1);
}

const summary = parsedTweets.map(tweetToCheckRunSummary).join("\n\n---\n\n");

const response = await octokit.request(
"POST /repos/:owner/:repo/check-runs",
{
Expand All @@ -54,18 +56,26 @@ async function createCheckRun(
conclusion: allTweetsValid ? "success" : "failure",
output: {
title: `${parsedTweets.length} tweet(s)`,
summary: parsedTweets.map(tweetToCheckRunSummary).join("\n\n---\n\n"),
summary
},
}
);

toolkit.info(`check run created: ${response.data.html_url}`);

// post preview to the PR conversation
await octokit.rest.issues.createComment({
owner: payload.repository.owner.login,
repo: payload.repository.name,
issue_number: payload.pull_request.number,
body: `## Added ${parsedTweets.length} tweet(s)\n\n${summary}`,
});
}

function tweetToCheckRunSummary(tweet) {
let text = autoLink(tweet.text)
.replace(/(^|\n)/g, "$1> ")
.replace(/(^|\n)> (\n|$)/g, "$1>$2");
.replace(/(^|\n)/g, "$1> ")
.replace(/(^|\n)> (\n|$)/g, "$1>$2");

if (!tweet.valid)
return `### ❌ Invalid\n\n${text}\n\n${tweet.error || "Unknown error"}`;
Expand Down

0 comments on commit dd2ebac

Please sign in to comment.