Skip to content

Commit c4dab6d

Browse files
author
Ian Walter
committedOct 9, 2021
Get list of changed files from GitHub instead of git diff-tree
1 parent 99850fb commit c4dab6d

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed
 

‎.changeset/flat-gifts-yawn.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"changeset-action": patch
3+
---
4+
5+
Get list of changed files from GitHub instead of git diff-tree

‎index.js

+16-9
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ const ignoredFiles = ['package-lock.json', 'pnpm-lock.yaml', 'yarn.lock']
1313

1414
async function run () {
1515
// Try to extract changeset data from the workflow context.
16-
if (process.env.DEBUG) logger.debug('Context', github.context)
17-
let { type, name, summary } = github.context.payload.inputs || {}
16+
logger.debug('Context', github.context)
17+
let { type, name, summary, token } = github.context.payload.inputs || {}
1818

1919
// Try to extract changeset data from the pull request label or workflow
2020
// input.
21-
const labels = github.context.payload?.pull_request?.labels || []
21+
const { labels = [], base, head } = github.context.payload?.pull_request || {}
2222
if (!type) {
2323
for (const label of labels) {
2424
const [ns, t] = label.name.split('.')
@@ -36,17 +36,24 @@ async function run () {
3636
if (name) {
3737
releases.push({ name, type })
3838
} else {
39-
const { stdout } = await execa(
40-
'git',
41-
['diff-tree', '--no-commit-id', '--name-only', '-r', 'HEAD', '--']
42-
)
43-
for (const file of stdout.split('\n')) {
39+
// Get the list of changed files from GitHub.
40+
const octokit = github.getOctokit(token)
41+
const res = await octokit.repos.compareCommits({
42+
base: base.sha,
43+
head: head.sha,
44+
owner: github.context.repo.owner,
45+
repo: github.context.repo.repo
46+
})
47+
48+
logger.info('Files', res.data.files)
49+
50+
for (const file of res.data.files) {
4451
if (!ignoredFiles.includes(file)) {
4552
const cwd = path.resolve(path.dirname(file))
4653
const { packageJson, ...pkg } = await readPackageUpAsync({ cwd })
4754
const hasPackage = releases.some(r => r.name === packageJson.name)
4855
if (!hasPackage) releases.push({ name: packageJson.name, type })
49-
logger.info('Git change found', { file, ...pkg, cwd, hasPackage })
56+
logger.debug('File', { file, ...pkg, cwd, hasPackage })
5057
}
5158
}
5259
}

0 commit comments

Comments
 (0)