Last active
May 5, 2019 06:49
-
-
Save wisetc/c541b36fc1ba99ea49db9e99b5e4425f to your computer and use it in GitHub Desktop.
将 react web 项目更新记录到表
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @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