Skip to content

Commit 7e4a86b

Browse files
committed
refactor: build app
1 parent b69d426 commit 7e4a86b

File tree

2 files changed

+40
-18
lines changed

2 files changed

+40
-18
lines changed

.github/workflows/pr-metadata.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: PR metadata annotation
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, synchronize]
6+
7+
jobs:
8+
9+
annotate-pr:
10+
runs-on: ubuntu-latest
11+
name: Annotates pull request with metadata
12+
steps:
13+
- name: Annotate PR
14+
uses: link-/PR-metadata-action@main
15+
with:
16+
path: "dist/"
17+
token: "test"

dist/index.js

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8865,30 +8865,35 @@ const github = __nccwpck_require__(5438);
88658865

88668866
const main = async () => {
88678867
try {
8868-
const owner = core.getInput('paths', { required: true });
8868+
const path = core.getInput('path', { required: true });
88698869
const token = core.getInput('token', { required: true });
8870+
const regExp = RegExp(path)
88708871
const octokit = new github.getOctokit(token);
88718872

8872-
const { data: changedFiles } = await octokit.rest.pulls.listFiles({
8873-
owner,
8874-
repo,
8875-
pull_number: pr_number,
8876-
});
8873+
const response = await octokit.rest.repos.compareCommits({
8874+
owner: github.context.repo.owner,
8875+
repo: github.context.repo.repo,
8876+
base: "HEAD^",
8877+
head: "HEAD"
8878+
})
88778879

8878-
let diffData = {
8879-
additions: 0,
8880-
deletions: 0,
8881-
changes: 0
8882-
};
8880+
const filteredFiles = (response.data.files || []).filter(file => {
8881+
let isMatch = regExp.test(file.filename)
8882+
console.log(`[${isMatch && '[** match **]'} ${file.filename}`)
8883+
console.log(`##Path: ${file.filename} matches`)
8884+
return isMatch
8885+
})
8886+
8887+
if(filteredFiles.length === 0){
8888+
console.log("No matchs found.")
8889+
console.log(`Raw input: ${directory}`)
8890+
console.log(`Regex: ${regExp.toString()}`)
8891+
core.setOutput("hasChanges", false)
8892+
}
88838893

8884-
diffData = changedFiles.reduce((acc, file) => {
8885-
acc.additions += file.additions;
8886-
acc.deletions += file.deletions;
8887-
acc.changes += file.changes;
8888-
return acc;
8889-
}, diffData);
8894+
console.log(`Found a total of ${filteredFiles.length} matches`)
88908895

8891-
console.log(changedFiles);
8896+
core.setOutput("hasChanges", true)
88928897

88938898
} catch (error) {
88948899
core.setFailed(error.message);

0 commit comments

Comments
 (0)