@@ -61,11 +61,13 @@ function extractIssueNumberFromRef(ref: string): number | undefined {
6161/**更新 plugins.json
6262 * 并提交到 Git
6363 */
64- async function updatePluginsFileAndCommit (
65- pluginInfo : PluginInfo
64+ async function updatePluginsFileAndCommitPush (
65+ pluginInfo : PluginInfo ,
66+ branchName : string
6667) : Promise < void > {
6768 if ( process . env . GITHUB_WORKSPACE ) {
68- const pluginJsonFilePath = `${ process . env . GITHUB_WORKSPACE } /docs/.vuepress/public/plugins.json`
69+ const path : string = core . getInput ( 'path' , { required : true } )
70+ const pluginJsonFilePath = `${ process . env . GITHUB_WORKSPACE } /${ path } `
6971 // 写入新数据
7072 fs . readFile ( pluginJsonFilePath , 'utf8' , ( err , data ) => {
7173 if ( err ) {
@@ -88,6 +90,7 @@ async function updatePluginsFileAndCommit(
8890 await exec . exec ( 'git' , [ 'config' , '--global' , 'user.email' , useremail ] )
8991 await exec . exec ( 'git' , [ 'add' , '-A' ] )
9092 await exec . exec ( 'git' , [ 'commit' , '-m' , commitMessage ] )
93+ await exec . exec ( 'git' , [ 'push' , 'origin' , branchName , '-f' ] )
9194 }
9295}
9396
@@ -152,11 +155,11 @@ async function createPullRequest(
152155 issue_number : pr . data . number ,
153156 labels : [ 'Plugin' ]
154157 } )
155- } catch ( e ) {
156- if ( e . message . includes ( `A pull request already exists for` ) ) {
157- core . info ( '拉取请求已经创建,请查看 ' )
158+ } catch ( error ) {
159+ if ( error . message . includes ( `A pull request already exists for` ) ) {
160+ core . info ( '该分支的拉取请求已创建,请前往查看 ' )
158161 } else {
159- throw e
162+ throw error
160163 }
161164 }
162165}
@@ -187,8 +190,6 @@ async function rebaseAllOpenPullRequests(
187190 await exec . exec ( 'git' , [ 'checkout' , '-b' , pull . head . ref ] )
188191 // 重置之前的提交
189192 await exec . exec ( 'git' , [ 'reset' , '--hard' , base ] )
190- // 合并修改
191- await exec . exec ( 'git' , [ 'merge' , base ] )
192193 const issue_number = extractIssueNumberFromRef ( pull . head . ref )
193194 if ( issue_number ) {
194195 core . info ( `正在处理 ${ pull . title } ` )
@@ -200,9 +201,10 @@ async function rebaseAllOpenPullRequests(
200201 issue . data . body ,
201202 issue . data . user . login
202203 )
203- await updatePluginsFileAndCommit ( pluginInfo )
204- await exec . exec ( 'git' , [ 'push' , 'origin' , pull . head . ref , '-f' ] )
204+ await updatePluginsFileAndCommitPush ( pluginInfo , pull . head . ref )
205205 core . info ( `拉取请求更新完毕` )
206+ } else {
207+ core . setFailed ( `无法获取 ${ pull . title } 对应的议题` )
206208 }
207209 }
208210}
@@ -239,8 +241,12 @@ async function run(): Promise<void> {
239241 const ref : string = github . context . payload . pull_request ?. head . ref
240242 const relatedIssueNumber = extractIssueNumberFromRef ( ref )
241243 if ( relatedIssueNumber ) {
242- closeIssue ( relatedIssueNumber , octokit )
244+ await closeIssue ( relatedIssueNumber , octokit )
245+ core . info ( `议题 #${ relatedIssueNumber } 已关闭` )
246+ await exec . exec ( 'git' , [ 'push' , 'origin' , '--delete' , ref ] )
243247 }
248+ } else {
249+ core . info ( '不是拉取请求关闭事件,已跳过' )
244250 }
245251 return
246252 }
@@ -249,8 +255,11 @@ async function run(): Promise<void> {
249255 if ( github . context . eventName === 'push' ) {
250256 const commitMessage : string = github . context . payload . head_commit . message
251257 if ( commitMessage . includes ( ':beers: publish' ) ) {
258+ core . info ( '发现提交为插件发布,准备更新拉取请求的提交' )
252259 const pullRequests = await getAllPluginPullRequest ( octokit )
253260 rebaseAllOpenPullRequests ( pullRequests , base , octokit )
261+ } else {
262+ core . info ( '该提交不是插件发布,已跳过' )
254263 }
255264 return
256265 }
@@ -282,10 +291,7 @@ async function run(): Promise<void> {
282291
283292 // 更新 plugins.json 并提交更改
284293 const pluginInfo = extractPluginInfo ( issueBody , username )
285- await updatePluginsFileAndCommit ( pluginInfo )
286-
287- // 提交更改到远程分支
288- await exec . exec ( 'git' , [ 'push' , 'origin' , branchName , '-f' ] )
294+ await updatePluginsFileAndCommitPush ( pluginInfo , branchName )
289295
290296 // 提交 Pull Request
291297 // 标题里要注明 issue 编号
0 commit comments