Skip to content

Commit

Permalink
chore: Update comment (#20904)
Browse files Browse the repository at this point in the history
* chore: Update comment

* wording
  • Loading branch information
zombieJ committed Jan 14, 2020
1 parent 5556ab5 commit 150ca1d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
9 changes: 7 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ stages:
versionSpec: '12.13.1'
- script: npm install
displayName: 'Install modules'
- script: |
node ./scripts/azure-github-comment.js '![Prepare preview](https://user-images.githubusercontent.com/5378891/72351368-2c979e00-371b-11ea-9652-eb4e825d745e.gif)'
displayName: 'Comment on github'
- script: npm run site
displayName: 'Build sites'
- script: ls -al _site/
Expand All @@ -34,5 +37,7 @@ stages:
export DEPLOY_DOMAIN=https://preview-${SYSTEM_PULLREQUEST_PULLREQUESTNUMBER}-ant-design.surge.sh
echo "Deploy to $DEPLOY_DOMAIN"
npx surge --project ./_site --domain $DEPLOY_DOMAIN
curl -X POST -u ${ACCESS_TOKEN} -H "Accept: application/json" -H "Content-Type:application/json" https://api.github.com/repos/ant-design/ant-design/issues/${SYSTEM_PULLREQUEST_PULLREQUESTNUMBER}/comments -d '{ "body": "Preview deploy to '${DEPLOY_DOMAIN}'" }'
displayName: 'Deploy Site'
displayName: 'Deploy Site'
- script: |
node ./scripts/azure-github-comment.js "Preview deployed to https://preview-${SYSTEM_PULLREQUEST_PULLREQUESTNUMBER}-ant-design.surge.sh"
displayName: 'Update comment on github'
55 changes: 55 additions & 0 deletions scripts/azure-github-comment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const fetch = require('node-fetch');

const REPO = process.env.ACCESS_REPO;
const TOKEN = process.env.ACCESS_TOKEN;
const PR = process.env.SYSTEM_PULLREQUEST_PULLREQUESTNUMBER;
const REPLACE_MARK = '<!-- AZURE_UPDATE_COMMENT -->';

const argv = process.argv;

const comment = argv[argv.length - 1];

const wrappedComment = `
${REPLACE_MARK}
${comment}
`.trim();

async function withGithub(url, json, method) {
const res = await fetch(url, {
method: method || (json ? 'POST' : 'GET'),
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: `Basic ${Buffer.from(TOKEN).toString('base64')}`,
},
body: json ? JSON.stringify(json) : undefined,
});

return res.json();
}

(async function run() {
const comments = await withGithub(`https://api.github.com/repos/${REPO}/issues/${PR}/comments`);

// Find my comment
const updateComment = comments.find(({ body }) => body.includes(REPLACE_MARK));
console.log('Origin comment:', updateComment);

// Update
let res;
if (!updateComment) {
res = await withGithub(`https://api.github.com/repos/${REPO}/issues/${PR}/comments`, {
body: wrappedComment,
});
} else {
res = await withGithub(
`https://api.github.com/repos/${REPO}/issues/comments/${updateComment.id}`,
{
body: wrappedComment,
},
'PATCH',
);
}

console.log(res);
})();

0 comments on commit 150ca1d

Please sign in to comment.