File tree 2 files changed +75
-0
lines changed
2 files changed +75
-0
lines changed Original file line number Diff line number Diff line change
1
+ name : CI
2
+
3
+ on : [pull_request]
4
+
5
+ defaults :
6
+ run :
7
+ shell : bash
8
+
9
+ jobs :
10
+ tag-alert-blocks :
11
+ name : Tag alert blocks
12
+ runs-on : ubuntu-latest
13
+ steps :
14
+ - uses : actions/checkout@v2
15
+ - run : |
16
+ git fetch --no-tags --prune --depth=1 origin +refs/heads/master:refs/remotes/origin/master
17
+ - uses : actions/github-script@v1
18
+ with :
19
+ github-token : ${{secrets.GITHUB_TOKEN}}
20
+ script : |
21
+ const path = require('path')
22
+ const { isUsingAlertBlock } = require(path.resolve(process.cwd(), 'scripts/tag-alert-blocks.js'))
23
+
24
+ isUsingAlertBlock().then(ok => {
25
+ if (ok) {
26
+ github.issues.addLabels({
27
+ issue_number: context.issue.number,
28
+ owner: context.repo.owner,
29
+ repo: context.repo.repo,
30
+ labels: ['review-alert-box']
31
+ })
32
+ }
33
+ })
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env node
2
+
3
+ const { exec } = require ( 'child_process' )
4
+
5
+ /**
6
+ * Execute a command and return stdout as string.
7
+ * @param {string } command
8
+ * @returns {Promise<string> }
9
+ */
10
+ function run ( command ) {
11
+ return new Promise ( ( resolve , reject ) => {
12
+ exec ( command , { encoding : 'utf-8' } , ( error , stdout ) =>
13
+ error ? reject ( error ) : resolve ( stdout )
14
+ )
15
+ } )
16
+ }
17
+
18
+ const ALERT_BLOCK = / ^ \+ \s * : : : \s ? ( \w + ) / m
19
+
20
+ async function isUsingAlertBlock ( base = 'origin/master' ) {
21
+ const result = await run ( `git diff --name-only ${ base } ` )
22
+ const files = (
23
+ await Promise . all (
24
+ result
25
+ . trim ( )
26
+ . split ( / \r ? \n / )
27
+ . map ( file =>
28
+ run ( `git diff ${ base } -- ${ file } ` )
29
+ . then ( diff => ALERT_BLOCK . test ( diff ) )
30
+ . then ( usesAlertBlock => ( usesAlertBlock ? file : '' ) )
31
+ )
32
+ )
33
+ ) . filter ( Boolean )
34
+
35
+ if ( files . length ) {
36
+ return true
37
+ }
38
+
39
+ return false
40
+ }
41
+
42
+ module . exports = { isUsingAlertBlock }
You can’t perform that action at this time.
0 commit comments