Skip to content

Commit

Permalink
fix test pr
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Jul 27, 2024
1 parent 127f35a commit 1298a04
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 31 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/test-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ on:

permissions:
contents: read
pull-requests: write

jobs:

Expand All @@ -33,6 +34,11 @@ jobs:
- run: npm run build
- run: npm run test-pr
env:
myToken: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FORCE_COLOR: true

- name: Generate list using Markdown
run: |
cat docs/pr/coverage-summary.md >> $GITHUB_STEP_SUMMARY
cat docs/pr/coverage-details.md >> $GITHUB_STEP_SUMMARY
72 changes: 42 additions & 30 deletions test/test-pr.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,39 @@ const getPullRequestChanges = async () => {
return [];
}

console.log('pull_request', github.context.payload.pull_request);

// This should be a token with access to your repository scoped in as a secret.
// The YML workflow will need to set myToken with the GitHub Secret Token
// myToken: ${{ secrets.GITHUB_TOKEN }}
// https://help.github.com/en/actions/automating-your-workflow-with-github-actions/authenticating-with-the-github_token#about-the-github_token-secret
const myToken = core.getInput('myToken');
console.log('myToken', `${myToken}`.length);

// const octokit = github.getOctokit(myToken);

// // You can also pass in additional options as a second parameter to getOctokit
// // const octokit = github.getOctokit(myToken, {userAgent: "MyActionVersion1"});

// const { data } = await octokit.rest.pulls.get({
// owner: 'octokit',
// repo: 'rest.js',
// pull_number: 123,
// mediaType: {
// format: 'diff'
// }
// });

// return data;
// console.log('pull_request', github.context.payload.pull_request);

/**
* env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
*/

const octokit = github.getOctokit(process.env.GITHUB_TOKEN);
const prNumber = github.context.payload.pull_request.number;
core.startGroup(`Fetching list of changed files for PR#${prNumber} from Github API`);

const iterator = octokit.paginate.iterator(
octokit.rest.pulls.listFiles, {
owner: github.context.repo.owner,
repo: github.context.repo.repo,
pull_number: prNumber,
per_page: 100
}
);

const files = [];
for await (const response of iterator) {
core.info(`Received ${response.data.length} items`);

for (const file of response.data) {
core.debug(`[${file.status}] ${file.filename}`);
if (['added', 'modified'].includes(file.status)) {
files.push(file.filename);
}
}
}

return files;
};


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

outputDir: './docs/pr',

sourceFilter: {
'**/src/**': true
},

onEnd: (coverageResults) => {

sourceFilter: (sourcePath) => {
if (prChanges.length) {
for (const file of prChanges) {
if (sourcePath.includes(file)) {
return true;
}
}
}
return false;
}
};

Expand Down

0 comments on commit 1298a04

Please sign in to comment.