Skip to content

Commit

Permalink
refactor: build app
Browse files Browse the repository at this point in the history
  • Loading branch information
fabidick22 committed Jun 16, 2022
1 parent b69d426 commit 7e4a86b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 18 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/pr-metadata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: PR metadata annotation

on:
pull_request:
types: [opened, reopened, synchronize]

jobs:

annotate-pr:
runs-on: ubuntu-latest
name: Annotates pull request with metadata
steps:
- name: Annotate PR
uses: link-/PR-metadata-action@main
with:
path: "dist/"
token: "test"
41 changes: 23 additions & 18 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8865,30 +8865,35 @@ const github = __nccwpck_require__(5438);

const main = async () => {
try {
const owner = core.getInput('paths', { required: true });
const path = core.getInput('path', { required: true });
const token = core.getInput('token', { required: true });
const regExp = RegExp(path)
const octokit = new github.getOctokit(token);

const { data: changedFiles } = await octokit.rest.pulls.listFiles({
owner,
repo,
pull_number: pr_number,
});
const response = await octokit.rest.repos.compareCommits({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
base: "HEAD^",
head: "HEAD"
})

let diffData = {
additions: 0,
deletions: 0,
changes: 0
};
const filteredFiles = (response.data.files || []).filter(file => {
let isMatch = regExp.test(file.filename)
console.log(`[${isMatch && '[** match **]'} ${file.filename}`)
console.log(`##Path: ${file.filename} matches`)
return isMatch
})

if(filteredFiles.length === 0){
console.log("No matchs found.")
console.log(`Raw input: ${directory}`)
console.log(`Regex: ${regExp.toString()}`)
core.setOutput("hasChanges", false)
}

diffData = changedFiles.reduce((acc, file) => {
acc.additions += file.additions;
acc.deletions += file.deletions;
acc.changes += file.changes;
return acc;
}, diffData);
console.log(`Found a total of ${filteredFiles.length} matches`)

console.log(changedFiles);
core.setOutput("hasChanges", true)

} catch (error) {
core.setFailed(error.message);
Expand Down

0 comments on commit 7e4a86b

Please sign in to comment.