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

Output the stat data #126

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Output the stat data #126

wants to merge 4 commits into from

Conversation

lykahb
Copy link

@lykahb lykahb commented Feb 22, 2022

Getting more data about the changes that are grouped by path would unlock new ways to use this action.

My motivation is to get enough data to make a comment with changes broken down by the filter groups - see the example. Another usecase would be to have a condition that applies a label depending on the number of lines changed. For example, marking a PR with few changes in src as easy to review.

There is a new output {key}_stat with a JSON/CSV that has the numstat data, aggregated by the filter groups. In effect, the data is similar to what one would get by calling git diff --shortstat <diff_refs> <list of filter globs> for each filter group.

Here are the details:

  • Create FileNumstat and FileStatus and rename the existing functions that deal with git diff to mention status.
  • Add calls git diff --numstat for all scenarios of getting the data from git
  • Extract a few inline git diff calls into a function, and decouple fixing line termination from ending the github action groups
  • Add an optional parameter to export the stats
  • Create a new filter group other for the files not matched by any filters. This is not related to the numstat changes but supports the usecase for commenting the breakdown of changes.

The only observable change for the existing users should be the addition of a new group other.

export async function listAllFilesAsAdded(): Promise<File[]> {
return core.group(`Listing all files tracked by git`, async () => {
const emptyTreeHash = (await exec('git', ['hash-object', '-t', 'tree', '/dev/null'])).stdout
return getGitDiffStatusNumstat(emptyTreeHash)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The git ls-files does not return the data about the number of lines added. Comparing the current revision to an empty tree both allows getting the stat data, and lets us reuse the existing diff logic.

const matchingFilenamesList = Object.values(result).flatMap(filteredFiles => filteredFiles.map(file => file.filename))
const matchingFilenamesSet = new Set(matchingFilenamesList)
result.other = files.filter(file => !matchingFilenamesSet.has(file.filename))
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there already was a filter group named other, it won't be overwritten. If the config did not have it, adding a new non-declared group should be safe - the keys are not in JSON, so it is unlikely that there exists logic in a step that uses paths-filter output that discovers the keys rather than uses the hardcoded names.

@lykahb lykahb force-pushed the numstat branch 3 times, most recently from 1396714 to 81575a9 Compare March 11, 2022 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant