Created
June 23, 2023 20:05
-
-
Save platinummonkey/0b6c991040e758cdae38746d20d4b4fb to your computer and use it in GitHub Desktop.
fast github pr diffs with deep history without full cloning or iterative enrichment
This file contains hidden or 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
| name: SOMETHING | |
| on: | |
| pull_request: | |
| types: | |
| - opened | |
| branches: | |
| - main | |
| jobs: | |
| check-something: | |
| runs-on: ubuntu-latest | |
| name: Print Diff Paths | |
| timeout-minutes: 60 | |
| steps: | |
| - uses: actions/setup-node@v3 | |
| with: | |
| node-version: 18 | |
| - name: Clone & checkout git repo | |
| uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 1 | |
| - name: Print Diff Paths | |
| uses: actions/github-script@v6 | |
| with: | |
| script: | | |
| const script = require('./.github/workflows/script.js'); | |
| await script({ github, context, core }); |
This file contains hidden or 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
| // @ts-check | |
| const fsp = require("node:fs/promises"); | |
| // The params are ones provided by https://github.com/actions/github-script runtime. | |
| module.exports = async ({ github, context, core }) => { | |
| const prMetadata = { | |
| owner: "YOUR_OWNER", | |
| repo: "YOUR_REPO", | |
| pull_number: context.payload.pull_request.number, | |
| }; | |
| const diffPaths = await getDiffPaths({ github, prMetadata }); | |
| } | |
| async function getDiffPaths({ github, prMetadata }) { | |
| /** | |
| * `data` is an array of items that look like this: | |
| * { | |
| * filename: 'some/special/path/foo.ini', | |
| * status: 'modified', | |
| * additions: 14, | |
| * deletions: 14, | |
| * patch: '@@ -1,2 +1,2 @@\n' + | |
| * ' [my_section]\n' + | |
| * '-baz = 12345\n' + | |
| * '+baz = 56789\n' | |
| * } | |
| */ | |
| const { data } = await github.rest.pulls.listFiles(prMetadata); | |
| /** @type string[] */ | |
| const diffPaths = data.map((item) => item.filename); | |
| console.log("(Debug) Diff paths: " + diffPaths.join(", ")); | |
| return diffPaths; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment