Skip to content

Commit 1298a04

Browse files
committed
fix test pr
1 parent 127f35a commit 1298a04

File tree

2 files changed

+49
-31
lines changed

2 files changed

+49
-31
lines changed

.github/workflows/test-pr.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ on:
1313

1414
permissions:
1515
contents: read
16+
pull-requests: write
1617

1718
jobs:
1819

@@ -33,6 +34,11 @@ jobs:
3334
- run: npm run build
3435
- run: npm run test-pr
3536
env:
36-
myToken: ${{ secrets.GITHUB_TOKEN }}
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3738
FORCE_COLOR: true
39+
40+
- name: Generate list using Markdown
41+
run: |
42+
cat docs/pr/coverage-summary.md >> $GITHUB_STEP_SUMMARY
43+
cat docs/pr/coverage-details.md >> $GITHUB_STEP_SUMMARY
3844

test/test-pr.js

+42-30
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,39 @@ const getPullRequestChanges = async () => {
1010
return [];
1111
}
1212

13-
console.log('pull_request', github.context.payload.pull_request);
14-
15-
// This should be a token with access to your repository scoped in as a secret.
16-
// The YML workflow will need to set myToken with the GitHub Secret Token
17-
// myToken: ${{ secrets.GITHUB_TOKEN }}
18-
// https://help.github.com/en/actions/automating-your-workflow-with-github-actions/authenticating-with-the-github_token#about-the-github_token-secret
19-
const myToken = core.getInput('myToken');
20-
console.log('myToken', `${myToken}`.length);
21-
22-
// const octokit = github.getOctokit(myToken);
23-
24-
// // You can also pass in additional options as a second parameter to getOctokit
25-
// // const octokit = github.getOctokit(myToken, {userAgent: "MyActionVersion1"});
26-
27-
// const { data } = await octokit.rest.pulls.get({
28-
// owner: 'octokit',
29-
// repo: 'rest.js',
30-
// pull_number: 123,
31-
// mediaType: {
32-
// format: 'diff'
33-
// }
34-
// });
35-
36-
// return data;
13+
// console.log('pull_request', github.context.payload.pull_request);
14+
15+
/**
16+
* env:
17+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18+
*/
19+
20+
const octokit = github.getOctokit(process.env.GITHUB_TOKEN);
21+
const prNumber = github.context.payload.pull_request.number;
22+
core.startGroup(`Fetching list of changed files for PR#${prNumber} from Github API`);
23+
24+
const iterator = octokit.paginate.iterator(
25+
octokit.rest.pulls.listFiles, {
26+
owner: github.context.repo.owner,
27+
repo: github.context.repo.repo,
28+
pull_number: prNumber,
29+
per_page: 100
30+
}
31+
);
32+
33+
const files = [];
34+
for await (const response of iterator) {
35+
core.info(`Received ${response.data.length} items`);
36+
37+
for (const file of response.data) {
38+
core.debug(`[${file.status}] ${file.filename}`);
39+
if (['added', 'modified'].includes(file.status)) {
40+
files.push(file.filename);
41+
}
42+
}
43+
}
44+
45+
return files;
3746
};
3847

3948

@@ -72,12 +81,15 @@ const test = async () => {
7281

7382
outputDir: './docs/pr',
7483

75-
sourceFilter: {
76-
'**/src/**': true
77-
},
78-
79-
onEnd: (coverageResults) => {
80-
84+
sourceFilter: (sourcePath) => {
85+
if (prChanges.length) {
86+
for (const file of prChanges) {
87+
if (sourcePath.includes(file)) {
88+
return true;
89+
}
90+
}
91+
}
92+
return false;
8193
}
8294
};
8395

0 commit comments

Comments
 (0)