Skip to content
This repository was archived by the owner on Apr 2, 2021. It is now read-only.

Make GitHub comments less spammy #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 42 additions & 10 deletions scripts/post-deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ const request = require('request');
const utils = require('./utils');
const config = require('./config');
const log = require('./log');

function getIssueUrl() {
const user = config.githubUsername;
const token = config.githubToken;
const org = config.githubOrg;
const repo = config.githubRepo;
const pr = config.githubPullRequestId;

return `https://${user}:${token}@api.github.com/repos/${org}/${repo}/issues/${pr}/comments`;
}

module.exports = function postDeploy() {
const expUrl = `https://expo.io/@${config.expUsername}/${utils.readPackageJSON().name}`;
const expUrlForQRCode = `https://exp.host/@${config.expUsername}/${utils.readPackageJSON().name}`;
Expand All @@ -20,21 +31,42 @@ module.exports = function postDeploy() {
`;

if (config.githubPullRequestId) {
const issueUrl = `https://${config.githubUsername}:${config.githubToken}@api.github.com/repos/${config.githubOrg}/${config.githubRepo}/issues/${config.githubPullRequestId}/comments`;
const issueUrl = getIssueUrl();
log('GitHub Issue URL', issueUrl);
request.post(

request.get(
{
url: issueUrl,
headers: { 'User-Agent': 'ci' },
body: JSON.stringify({ body })
headers: { 'User-Agent': 'ci' }
},
(error, response) => {
if (error) {
console.error('Failed to post comment to GitHub, an error occurred', error);
} else if (response.statusCode >= 400) {
console.error('Failed to post comment to GitHub, request failed with', response);
(getError, getResponse) => {
if (getError) {
console.error('Failed to check comments on GitHub, an error occurred', getError);
} else if (getResponse.statusCode >= 400) {
console.error('Failed to check comments on GitHub, request failed with', getResponse);
} else {
console.log(`Posted message to GitHub PR #${config.githubPullRequestId}`);
const comments = JSON.parse(getResponse.body);
if (!comments.filter(comment => comment.body === body).length) {
request.post(
{
url: issueUrl,
headers: { 'User-Agent': 'ci' },
body: JSON.stringify({ body })
},
(postError, postResponse) => {
if (postError) {
console.error('Failed to post comment to GitHub, an error occurred', postError);
} else if (postResponse.statusCode >= 400) {
console.error(
'Failed to post comment to GitHub, request failed with',
postResponse
);
} else {
console.log(`Posted message to GitHub PR #${config.githubPullRequestId}`);
}
}
);
}
}
}
);
Expand Down