Skip to content

Instantly share code, notes, and snippets.

@wisetc
Last active May 5, 2019 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wisetc/c541b36fc1ba99ea49db9e99b5e4425f to your computer and use it in GitHub Desktop.
Save wisetc/c541b36fc1ba99ea49db9e99b5e4425f to your computer and use it in GitHub Desktop.
将 react web 项目更新记录到表
// @format
const util = require('util');
const exec = util.promisify(require('child_process').exec);
async function getCommitMessage() {
const {stdout} = await exec('echo $(git log -1 --pretty="%B") | tr -d "\n"');
return stdout;
}
async function getAuthor() {
const {stdout} = await exec(
'echo $(git log -1 --pretty="%an <%ae>") | tr -d "\n"',
);
return stdout;
}
async function getHash() {
const {stdout} = await exec('echo $(git log -1 --pretty="%H") | tr -d "\n"');
return stdout;
}
async function getPostBody() {
const content = await getCommitMessage();
const creator = await getAuthor();
const version = await getHash();
const body = {
content,
creator,
product: 'wechat',
version,
};
let ret = '';
for (const k in body) {
let value = encodeURIComponent(body[k]);
ret += `&${k}=${value}`;
}
return ret.slice(1);
}
async function saveBuild() {
const postBody = await getPostBody();
const url = 'http://localhost:28225/savebuild';
const shellCmd = `curl "${url}" -d "${postBody}"`;
console.log(shellCmd);
const {stdout, stderr} = await exec(shellCmd);
stdout && console.log(stdout);
stderr && console.log(stderr);
return stdout;
}
saveBuild();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment