diff --git a/dist/index.js b/dist/index.js index e814b20..4631371 100644 --- a/dist/index.js +++ b/dist/index.js @@ -8863,41 +8863,47 @@ var __webpack_exports__ = {}; const core = __nccwpck_require__(2186); const github = __nccwpck_require__(5438); -const main = async () => { - try { - 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 response = await octokit.rest.repos.compareCommits({ - owner: github.context.repo.owner, - repo: github.context.repo.repo, - base: "HEAD^", - head: "HEAD" - }) - - 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 +async function setOutputs(files) { + const pathsChanged = [] + const filesChanged = [] + files.forEach(file => { + pathsChanged.push(file.filename.split("/").slice(0, -1).join("/")) + filesChanged.push(file.filename) }) + core.setOutput("paths_changed", JSON.stringify(pathsChanged)) + core.setOutput("file_changed", JSON.stringify(filesChanged)) +} - if(filteredFiles.length === 0){ - console.log("No matchs found.") - console.log(`Raw input: ${directory}`) - console.log(`Regex: ${regExp.toString()}`) - core.setOutput("hasChanges", false) - } +const main = async () => { + try { + const path = core.getInput('path', {required: false}) || "./" + const token = core.getInput('token', {required: true}) + const pr = github.context.payload.pull_request + const regExp = RegExp(path) + const octokit = new github.getOctokit(token); + + const response = await octokit.rest.pulls.listFiles({ + owner: github.context.repo.owner, + repo: github.context.repo.repo, + pull_number: pr.number + }) - console.log(`Found a total of ${filteredFiles.length} matches`) + const filteredFiles = (response.data || []).filter(file => { + let isMatch = regExp.test(file.filename) + console.log(`- ${isMatch} [** match **] ${file.filename}`) + return isMatch + }) - core.setOutput("hasChanges", true) + if (filteredFiles.length === 0) { + console.log("No matchs found.") + console.log(`Raw input: ${directory}`) + console.log(`Regex: ${regExp.toString()}`) + } + await setOutputs(filteredFiles); - } catch (error) { - core.setFailed(error.message); - } + } catch (error) { + core.setFailed(error.message); + } } main();