@@ -28,98 +28,6 @@ const utils = {
2828 return fixedTimeComparison ( signature , request . headers [ 'x-hub-signature' ] )
2929 } ,
3030
31- /**
32- * 目录是否存在
33- *
34- * @param {string } file 路径
35- *
36- * @return {boolean }
37- */
38- isDirectory ( file ) {
39- try {
40- return fs . statSync ( file ) . isDirectory ( )
41- } catch ( e ) {
42- if ( e . code !== 'ENOENT' ) {
43- throw e
44- }
45-
46- return false
47- }
48- } ,
49-
50- /**
51- * 获取本地 git 目录的第一个提交,主要处理当第一次给项目打标签时不能用2个标签去 ..
52- *
53- * @param {string } options.dir git 目录
54- *
55- * @return {string }
56- */
57- getFirstCommitHash ( { dir } ) {
58- return execSync ( `cd ${ dir } && git log --oneline --pretty=format:"%h"` ) . toString ( )
59- . split ( / \n + / ) . slice ( - 1 ) [ 0 ]
60- } ,
61-
62- /**
63- * 获取本地 git 目录的日志
64- *
65- * @param {Object } options 配置数据
66- * @param {string } options.dir git 目录
67- * @param {string } options.before 开始版本号
68- * @param {string } options.after 结束版本号
69- * @param {string } options.html_url 预览的html地址, 用来拼 hash commit
70- * @param {boolean } [options.hash=false] 是否携带 commit hash log
71- *
72- * @return {Array }
73- */
74- getCommitLog ( options ) {
75- const shell = [
76- 'cd {dir}' ,
77- options . hash
78- ? 'git log {before}..{after} --no-merges --pretty=format:"- [%h]({html_url}/commit/%H) - %s, by @%aN <<%ae>>"'
79- : 'git log {before}..{after} --no-merges --pretty=format:"- %s, by @%aN <<%ae>>"'
80- ] . join ( ' && ' )
81-
82- return execSync ( format ( shell , options ) ) . toString ( ) . split ( / \n + / )
83- } ,
84-
85- /**
86- * 更新 github 项目
87- *
88- * @param {string } options.repo 项目名
89- *
90- * @return {Promise }
91- */
92- updateRepo ( { url, repo } ) {
93- const repoDir = path . resolve ( __dirname , '../github/' , repo )
94-
95- return new Promise ( ( resolve , reject ) => {
96- gitPullOrClone ( url , repoDir , err => {
97- if ( err ) {
98- return reject ( err )
99- }
100-
101- resolve ( repoDir )
102- } )
103- } )
104- } ,
105-
106- /**
107- * 获取本地 git 目录的 tag 列表
108- *
109- * @param {Object } options 配置
110- * @param {string } options.dir git 目录
111- *
112- * @return {Array }
113- */
114- getTags ( options ) {
115- const shell = [
116- 'cd {dir}' ,
117- 'git describe --tags `git rev-list --tags --abbrev=0` --abbrev=0 | uniq'
118- ] . join ( ' && ' )
119-
120- return execSync ( format ( shell , options ) ) . toString ( ) . split ( / \n + / ) . filter ( tag => ! ! tag )
121- } ,
122-
12331 /**
12432 * 获取 package.json 里的 config.github-bot
12533 *
0 commit comments