Created
September 15, 2022 16:07
-
-
Save lsongdev/f59aa3d051dcb4e78d27a1b09833320a to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>LGTM</title> | |
<style> | |
body { | |
width: 80%; | |
margin: auto; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>LGTM for Alipay Code</h1> | |
<h2>How to Use?</h2> | |
Drag | |
<a href="javascript:(function()%7Bconst%5B%2C%2C%2CgroupName%2CprojectName%2C%2CpullRequestId%5D%3Dlocation.href.split(%22%2F%22)%2Cproject%3D%5BgroupName%2CprojectName%5D.join(%22%2F%22)%2Ccomments%3D%5B%22LGTM%22%2C%22SGTM%22%2C%22%E4%B8%8D%E9%94%99%EF%BC%8C%E6%B2%A1%E9%97%AE%E9%A2%98%E3%80%82%22%2C%22%E5%8F%AF%E4%BB%A5%EF%BC%8C%E6%B2%A1%E9%97%AE%E9%A2%98%E3%80%82%22%2C%22%E7%9C%8B%E8%B5%B7%E6%9D%A5%E6%B2%A1%E9%97%AE%E9%A2%98%E3%80%82%22%2C%22%E5%8F%AF%E4%BB%A5%E5%A4%9A%E5%8A%A0%E7%82%B9%E6%B3%A8%E9%87%8A%E3%80%82%22%2C%22%E5%8A%9F%E8%83%BD%E6%B5%8B%E8%AF%95%E6%B2%A1%E9%97%AE%E9%A2%98%E5%90%A7%EF%BC%9F%22%2C%22%E5%8A%A0%E4%B8%80%E4%B8%8B%E7%9B%91%E6%8E%A7%E5%90%A7%22%2C%22%E5%BC%82%E5%B8%B8%E6%83%85%E5%86%B5%E7%9A%84%E5%A4%84%E7%90%86%E8%80%83%E8%99%91%E4%BA%86%E5%90%97%EF%BC%9F%22%5D%2Capi%3D%22https%3A%2F%2Fcode.alipay.com%2Fapi%2Fv3%22%2Cwebapi%3D%22https%3A%2F%2Fcode.alipay.com%2Fwebapi%22%2Cq%3D%22_output_charset%3Dutf-8%26_input_charset%3Dutf-8%22%2Csample%3De%3D%3Ee%5BMath.floor(Math.random()*e.length)%5D%2Cput%3De%3D%3Efetch(e%2C%7Bmethod%3A%22PUT%22%7D)%2CgetProjectByPath%3De%3D%3Efetch(%60%24%7Bwebapi%7D%2Fprojects%2F%24%7Be%7D%2F%3F%24%7Bq%7D%60).then(e%3D%3Ee.json())%2CgetPullRequestByIID%3D(e%2Ct)%3D%3Efetch(%60%24%7Bwebapi%7D%2Fprojects%2F%24%7Be%7D%2Fget_pull_request_by_iid%3Fiid%3D%24%7Bt%7D%26%24%7Bq%7D%60).then(e%3D%3Ee.json())%2Ccomment%3D(e%2Ct%2Co)%3D%3Eput(%60%24%7Bapi%7D%2Fprojects%2F%24%7Be%7D%2Fpull_requests%2F%24%7Bt%7D%2Freviews%3Fbody%3D%24%7BencodeURIComponent(o)%7D%26%24%7Bq%7D%60).then(e%3D%3Ee.json())%2Caccept%3D(e%2Ct)%3D%3Eput(%60%24%7Bapi%7D%2Fprojects%2F%24%7Be%7D%2Fpull_requests%2F%24%7Bt%7D%2Freview%2Faccept%3F%24%7Bq%7D%60).then(e%3D%3Ee.json())%3BPromise.resolve(project).then(encodeURIComponent).then(getProjectByPath).then(e%3D%3EgetPullRequestByIID(e.id%2CpullRequestId)).then(e%3D%3EPromise.all(%5Bcomment(e.target_project_id%2Ce.id%2Csample(comments))%2Caccept(e.target_project_id%2Ce.id)%5D)).then(e%3D%3Elocation.reload())%7D)()">LGTM</a> | |
to Bookmarks Bar | |
<h2>Source Code</h2> | |
<!-- HTML generated using hilite.me --><div style="background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #008800; font-weight: bold">const</span> [, , , groupName, projectName, , pullRequestId] <span style="color: #333333">=</span> location.href.split(<span style="background-color: #fff0f0">'/'</span>); | |
<span style="color: #008800; font-weight: bold">const</span> project <span style="color: #333333">=</span> [groupName, projectName].join(<span style="background-color: #fff0f0">'/'</span>); | |
<span style="color: #008800; font-weight: bold">const</span> comments <span style="color: #333333">=</span> [ | |
<span style="background-color: #fff0f0">'LGTM'</span>, | |
<span style="background-color: #fff0f0">'SGTM'</span>, | |
<span style="background-color: #fff0f0">'不错,没问题。'</span>, | |
<span style="background-color: #fff0f0">'可以,没问题。'</span>, | |
<span style="background-color: #fff0f0">'看起来没问题。'</span>, | |
<span style="background-color: #fff0f0">'可以多加点注释。'</span>, | |
<span style="background-color: #fff0f0">'功能测试没问题吧?'</span>, | |
<span style="background-color: #fff0f0">'加一下监控吧'</span>, | |
<span style="background-color: #fff0f0">'异常情况的处理考虑了吗?'</span>, | |
]; | |
<span style="color: #008800; font-weight: bold">const</span> api <span style="color: #333333">=</span> <span style="color: #FF0000; background-color: #FFAAAA">`</span>https<span style="color: #333333">:</span><span style="color: #888888">//code.alipay.com/api/v3`;</span> | |
<span style="color: #008800; font-weight: bold">const</span> webapi <span style="color: #333333">=</span> <span style="color: #FF0000; background-color: #FFAAAA">`</span>https<span style="color: #333333">:</span><span style="color: #888888">//code.alipay.com/webapi`;</span> | |
<span style="color: #008800; font-weight: bold">const</span> q <span style="color: #333333">=</span> <span style="color: #FF0000; background-color: #FFAAAA">`</span>_output_charset<span style="color: #333333">=</span>utf<span style="color: #333333">-</span><span style="color: #0000DD; font-weight: bold">8</span><span style="color: #333333">&</span>_input_charset<span style="color: #333333">=</span>utf<span style="color: #333333">-</span><span style="color: #0000DD; font-weight: bold">8</span><span style="color: #FF0000; background-color: #FFAAAA">`</span>; | |
<span style="color: #008800; font-weight: bold">const</span> sample <span style="color: #333333">=</span> arr <span style="color: #333333">=></span> | |
arr[<span style="color: #007020">Math</span>.floor(<span style="color: #007020">Math</span>.random() <span style="color: #333333">*</span> arr.length)]; | |
<span style="color: #008800; font-weight: bold">const</span> put <span style="color: #333333">=</span> url <span style="color: #333333">=></span> fetch(url, { method<span style="color: #333333">:</span> <span style="background-color: #fff0f0">'PUT'</span> }); | |
<span style="color: #008800; font-weight: bold">const</span> getProjectByPath <span style="color: #333333">=</span> (projectPath) <span style="color: #333333">=></span> | |
fetch(<span style="color: #FF0000; background-color: #FFAAAA">`</span>${webapi}<span style="color: #333333">/</span>projects<span style="color: #333333">/</span>${projectPath}<span style="color: #333333">/?</span>${q}<span style="color: #FF0000; background-color: #FFAAAA">`</span>) | |
.then(res <span style="color: #333333">=></span> res.json()); | |
<span style="color: #008800; font-weight: bold">const</span> getPullRequestByIID <span style="color: #333333">=</span> (projectId, pullRequestIID) <span style="color: #333333">=></span> | |
fetch(<span style="color: #FF0000; background-color: #FFAAAA">`</span>${webapi}<span style="color: #333333">/</span>projects<span style="color: #333333">/</span>${projectId}<span style="color: #333333">/</span>get_pull_request_by_iid<span style="color: #333333">?</span>iid<span style="color: #333333">=</span>${pullRequestIID}<span style="color: #333333">&</span>${q}<span style="color: #FF0000; background-color: #FFAAAA">`</span>) | |
.then(res <span style="color: #333333">=></span> res.json()); | |
<span style="color: #008800; font-weight: bold">const</span> comment <span style="color: #333333">=</span> (projectId, pullRequestId, message) <span style="color: #333333">=></span> | |
put(<span style="color: #FF0000; background-color: #FFAAAA">`</span>${api}<span style="color: #333333">/</span>projects<span style="color: #333333">/</span>${projectId}<span style="color: #333333">/</span>pull_requests<span style="color: #333333">/</span>${pullRequestId}<span style="color: #333333">/</span>reviews<span style="color: #333333">?</span>body<span style="color: #333333">=</span>${<span style="color: #007020">encodeURIComponent</span>(message)}<span style="color: #333333">&</span>${q}<span style="color: #FF0000; background-color: #FFAAAA">`</span>) | |
.then(res <span style="color: #333333">=></span> res.json()); | |
<span style="color: #008800; font-weight: bold">const</span> accept <span style="color: #333333">=</span> (projectId, pullRequestId) <span style="color: #333333">=></span> | |
put(<span style="color: #FF0000; background-color: #FFAAAA">`</span>${api}<span style="color: #333333">/</span>projects<span style="color: #333333">/</span>${projectId}<span style="color: #333333">/</span>pull_requests<span style="color: #333333">/</span>${pullRequestId}<span style="color: #333333">/</span>review<span style="color: #333333">/</span>accept<span style="color: #333333">?</span>${q}<span style="color: #FF0000; background-color: #FFAAAA">`</span>) | |
.then(res <span style="color: #333333">=></span> res.json()); | |
Promise | |
.resolve(project) | |
.then(<span style="color: #007020">encodeURIComponent</span>) | |
.then(getProjectByPath) | |
.then(project <span style="color: #333333">=></span> getPullRequestByIID(project.id, pullRequestId)) | |
.then(pullRequest <span style="color: #333333">=></span> Promise.all([ | |
comment(pullRequest.target_project_id, pullRequest.id, sample(comments)), | |
accept(pullRequest.target_project_id, pullRequest.id), | |
])).then(response <span style="color: #333333">=></span> location.reload()); | |
</pre></div> | |
<h2>Any Questions?</h2> | |
<address>[email protected]</address> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment