Browse Source

chore: Update comment (#20904)

* chore: Update comment

* wording
pull/20908/head
二货机器人 5 years ago
committed by GitHub
parent
commit
150ca1d49c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      azure-pipelines.yml
  2. 55
      scripts/azure-github-comment.js

7
azure-pipelines.yml

@ -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/
@ -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'
- 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
scripts/azure-github-comment.js

@ -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);
})();
Loading…
Cancel
Save