diff --git a/.github/workflows/jsonr.js b/.github/workflows/jsonr.js new file mode 100644 index 0000000000..6eb318178b --- /dev/null +++ b/.github/workflows/jsonr.js @@ -0,0 +1,50 @@ +const fs = require('fs'); + +// read json from stdin + +let buffer = Buffer.alloc(0); +const args = process.argv.slice(2); + +function getAttrByPath(object, pathText) { + const parts = pathText.split('.'); + let curr = object; + const REG1 = /\["(\w+)"\]/; + const REG2 = /\[(\w+)\]/; + const REG3 = /"(\w+)"/; + const REG4 = /(\w+)/; + const regList = [REG1, REG2, REG3, REG4]; + for (const p of parts) { + let mat; + let field = null; + for (let r of regList) { + mat = p.match(r); + if (mat) { + field = mat[1]; + break; + } + } + if (!field) { + console.error(`path component "${p}" is invalidate from ${pathText}`); + process.exit(1); + } + curr = curr[field]; + } + return curr; +} + + +process.stdin.resume(); + +process.stdin.on('data', data => { + buffer = Buffer.concat([buffer, data]); +}).on('end', () => { + const data = JSON.parse(buffer.toString('utf8')) + let value = getAttrByPath(data, args[0]); + if(args.length >= 2) { + const mat = value.match(new RegExp(args[1])); + if(mat) { + value = mat[args[2]]; + } + } + console.log(value); +}); diff --git a/.github/workflows/native-generated-pr.yml b/.github/workflows/native-generated-pr.yml new file mode 100644 index 0000000000..3c7fa72d72 --- /dev/null +++ b/.github/workflows/native-generated-pr.yml @@ -0,0 +1,43 @@ +name: Assign Generated PR + +# on: + # pull_request_target: + # types: [opened] + # paths: + # - 'native/cocos/bindings/auto/**' + +on: pull_request_target + +jobs: + auto-assign: + if: + (contains(github.event.pull_request.body, 'Automated PR to genbindings')) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Update assignees + id: merger + env: + PR_NUMBER: ${{github.event.number}} + # REPO_TOKEN: ${{secrets.GITHUB_TOKEN}} + # REPO_TOKEN: ${{secrets.PR_TOKEN}} + REPO_TOKEN: ${{secrets.LABEL_TOKEN}} + run: | + SRC_PR=`curl ${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/commits | \ + sh -c 'node ./.github/workflows/jsonr.js [0].commit.message "\(#(\w+)\)" 1'` + echo "Source PR: ${SRC_PR}" + SRC_MERGER=`curl -H "Accept: application/vnd.github+json" ${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/pulls/${SRC_PR} | \ + sh -c 'node ./.github/workflows/jsonr.js merged_by.login'` + echo "Source PR merger: ${SRC_MERGER}" + echo "Token Length: ${#REPO_TOKEN}" + echo ::set-output name=SRC_MERGER::${SRC_MERGER} + curl -X POST -H "Accept: application/vnd.github+json" \ + -H "Authorization: token $REPO_TOKEN" \ + ${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/assignees \ + -d '{"assignees":["${SRC_MERGER}"]}' + exit 0 + # - name: Assignment + # uses: PatriceJiang/auto-assignment@v1 + # with: + # token: ${{ secrets.LABEL_TOKEN }} + # users: '["${{steps.merger.outputs.SRC_MERGER}}"]' \ No newline at end of file