Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: switch to use name status #1230

Merged
merged 38 commits into from Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
696fc61
feat: switch to use name status
jackton1 Jun 6, 2023
e0e5314
Update utils.ts
jackton1 Jun 6, 2023
d71e67e
Update src/utils.ts
jackton1 Jun 6, 2023
6e0d298
Update to use --name-status
jackton1 Jun 14, 2023
96b272a
Apply suggestions from code review
jackton1 Jun 14, 2023
0236277
Update src/changedFiles.ts
jackton1 Jun 14, 2023
4c519e0
Fixed lint errors
jackton1 Jun 14, 2023
2aa7d0b
Fixed lint errors
jackton1 Jun 14, 2023
3fb0496
Fixed lint errors
jackton1 Jun 14, 2023
aef2054
Fixed lint errors
jackton1 Jun 14, 2023
d384c62
Fixed lint errors
jackton1 Jun 14, 2023
04ddeae
Fixed lint errors
jackton1 Jun 14, 2023
fd7732b
Fixed lint errors
jackton1 Jun 14, 2023
7759821
Fixed lint errors
jackton1 Jun 14, 2023
ea3c22b
Fixed lint errors
jackton1 Jun 14, 2023
493e22e
Fixed lint errors
jackton1 Jun 14, 2023
1be434e
Fixed lint errors
jackton1 Jun 14, 2023
8f457cd
Merge 1be434e90a605ea3f5fe9c92d29fb2714d0c0813 into 2d0b52f4408b791c0…
jackton1 Jun 14, 2023
1061a83
Added missing changes and modified dist assets.
actions-user Jun 14, 2023
0027e30
Fixed lint errors
jackton1 Jun 14, 2023
5deabaf
Merge 0027e30d62c1eaf8b85b240b5bd9accaa9fb74b1 into 2d0b52f4408b791c0…
jackton1 Jun 14, 2023
83a0003
Added missing changes and modified dist assets.
actions-user Jun 14, 2023
45993a8
Fixed test
jackton1 Jun 14, 2023
3ddf33f
Merge 45993a8e86776aa04e073c0624ed11d5978a2f42 into 2d0b52f4408b791c0…
jackton1 Jun 14, 2023
5ae7300
Added missing changes and modified dist assets.
actions-user Jun 14, 2023
7b11b86
Removed unused file
jackton1 Jun 14, 2023
bc4af49
Add debug messages
jackton1 Jun 14, 2023
42c04b1
Merge bc4af49787e222c2c40031ef2185756dc41a924c into 2d0b52f4408b791c0…
jackton1 Jun 14, 2023
9621129
Added missing changes and modified dist assets.
actions-user Jun 14, 2023
6247b0c
Updated debug message
jackton1 Jun 14, 2023
346c281
Updated filtered files
jackton1 Jun 14, 2023
91eb1dd
Merge 346c281e87d3fceea324ecb90f87dbd969248f39 into 2d0b52f4408b791c0…
jackton1 Jun 14, 2023
a152d84
Added missing changes and modified dist assets.
actions-user Jun 14, 2023
864665d
Update test-è.txt
jackton1 Jun 14, 2023
33ee83c
Fixed bug with empty sha
jackton1 Jun 14, 2023
474cf31
Updated error handling
jackton1 Jun 14, 2023
79c71d7
Merge 474cf31f9b7d9dff5ff962a06b96d1ded615db7b into 2d0b52f4408b791c0…
jackton1 Jun 14, 2023
c4af9c1
Added missing changes and modified dist assets.
actions-user Jun 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
776 changes: 632 additions & 144 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions dist/licenses.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -34,10 +34,12 @@
"dependencies": {
"@actions/core": "1.10.0",
"@actions/exec": "1.1.1",
"lodash": "^4.17.15",
"micromatch": "^4.0.5"
},
"devDependencies": {
"@types/jest": "29.5.2",
"@types/lodash": "^4.14.195",
"@types/micromatch": "^4.0.2",
"@types/node": "20.2.1",
"@types/uuid": "9.0.2",
Expand All @@ -51,6 +53,6 @@
"jest": "29.5.0",
"prettier": "2.8.8",
"ts-jest": "29.1.0",
"typescript": "5.1.3"
"typescript": "5.0.4"
}
}
119 changes: 96 additions & 23 deletions src/changedFiles.ts
Expand Up @@ -4,11 +4,13 @@ import {DiffResult} from './commitSha'
import {Inputs} from './inputs'
import {
getDirnameMaxDepth,
gitDiff,
gitRenamedFiles,
gitSubmoduleDiffSHA,
jsonOutput
jsonOutput,
getAllChangedFiles,
ChangeTypeEnum
} from './utils'
import flatten from 'lodash/flatten'

export const getRenamedFiles = async ({
inputs,
Expand Down Expand Up @@ -68,30 +70,26 @@ export const getRenamedFiles = async ({
return renamedFiles.join(inputs.oldNewFilesSeparator)
}

export const getDiffFiles = async ({
inputs,
export type ChangedFiles = {
[key in ChangeTypeEnum]: string[]
jackton1 marked this conversation as resolved.
Show resolved Hide resolved
}

export const getAllDiffFiles = async ({
workingDirectory,
hasSubmodule,
diffResult,
diffFilter,
filePatterns = [],
submodulePaths
}: {
inputs: Inputs
workingDirectory: string
hasSubmodule: boolean
diffResult: DiffResult
diffFilter: string
filePatterns?: string[]
submodulePaths: string[]
}): Promise<string> => {
let files = await gitDiff({
}): Promise<ChangedFiles> => {
const files = await getAllChangedFiles({
cwd: workingDirectory,
sha1: diffResult.previousSha,
sha2: diffResult.currentSha,
diff: diffResult.diff,
diffFilter,
filePatterns
diff: diffResult.diff
})

if (hasSubmodule) {
Expand All @@ -110,32 +108,107 @@ export const getDiffFiles = async ({
)

if (submoduleShaResult.currentSha && submoduleShaResult.previousSha) {
const submoduleFiles = await gitDiff({
const submoduleFiles = await getAllChangedFiles({
cwd: submoduleWorkingDirectory,
sha1: submoduleShaResult.previousSha,
sha2: submoduleShaResult.currentSha,
diff: diffResult.diff,
diffFilter,
isSubmodule: true,
filePatterns,
parentDir: submodulePath
})
files.push(...submoduleFiles)

for (const changeType of Object.keys(
submoduleFiles
) as ChangeTypeEnum[]) {
jackton1 marked this conversation as resolved.
Show resolved Hide resolved
jackton1 marked this conversation as resolved.
Show resolved Hide resolved
if (!files[changeType]) {
files[changeType] = []
}
files[changeType].push(...submoduleFiles[changeType])
}
}
}
}

return files
}

function* getChangeTypeFilesGenerator({
inputs,
changedFiles,
changeTypes
}: {
inputs: Inputs
changedFiles: ChangedFiles
changeTypes: ChangeTypeEnum[]
jackton1 marked this conversation as resolved.
Show resolved Hide resolved
jackton1 marked this conversation as resolved.
Show resolved Hide resolved
}): Generator<string> {
for (const changeType of changeTypes) {
const files = changedFiles[changeType] || []
for (const file of files) {
if (inputs.dirNames) {
yield getDirnameMaxDepth({
pathStr: file,
dirNamesMaxDepth: inputs.dirNamesMaxDepth,
excludeCurrentDir:
inputs.dirNamesExcludeRoot || inputs.dirNamesExcludeCurrentDir
})
} else {
yield file
}
}
}
}

export const getChangeTypeFiles = async ({
inputs,
changedFiles,
changeTypes
}: {
inputs: Inputs
changedFiles: ChangedFiles
changeTypes: ChangeTypeEnum[]
jackton1 marked this conversation as resolved.
Show resolved Hide resolved
jackton1 marked this conversation as resolved.
Show resolved Hide resolved
}): Promise<string> => {
const files = [
...new Set(getChangeTypeFilesGenerator({inputs, changedFiles, changeTypes}))
]

if (inputs.json) {
return jsonOutput({value: files, shouldEscape: inputs.escapeJson})
}

return files.join(inputs.separator)
}

if (inputs.dirNames) {
files = files.map(file =>
getDirnameMaxDepth({
function* getAllChangeTypeFilesGenerator({
inputs,
changedFiles
}: {
inputs: Inputs
changedFiles: ChangedFiles
}): Generator<string> {
for (const file of flatten(Object.values(changedFiles))) {
if (inputs.dirNames) {
yield getDirnameMaxDepth({
pathStr: file,
dirNamesMaxDepth: inputs.dirNamesMaxDepth,
excludeCurrentDir:
inputs.dirNamesExcludeRoot || inputs.dirNamesExcludeCurrentDir
})
)
files = [...new Set(files)]
} else {
yield file
}
}
}

export const getAllChangeTypeFiles = async ({
inputs,
changedFiles
}: {
inputs: Inputs
changedFiles: ChangedFiles
}): Promise<string> => {
const files = [
...new Set(getAllChangeTypeFilesGenerator({inputs, changedFiles}))
]

if (inputs.json) {
return jsonOutput({value: files, shouldEscape: inputs.escapeJson})
Expand Down