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: track changed files for commit #200

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

Conversation

sspaink
Copy link

@sspaink sspaink commented Mar 3, 2022

What does this do / why do we need it?

  • What this change does is updates the Commit struct to track the changed files in the commit.
  • Why I would like this change is because I want to use the list of changed files to determine scope within the template. I am looking into using git-chglog for the Telegraf project and it isn't always guaranteed the scope is added correctly before a pull request is merged. Having the list of changed files can help update the template to get a best guess of the scope. Hopefully other users will also find this useful for potential other use cases?
Example template and output

template:

{{- $scope := .Scope -}}
{{- if not $scope -}}
    {{- range $changed := $commit.ChangedFiles -}}
        {{- if not $scope -}}
            {{- $paths := splitn "/" -1 (regexFind "plugins/(.*){2}/" $changed) -}}
            {{- $scope = join "." (list $paths._1 $paths._2) -}}
        {{- end -}}
    {{- end -}}
{{- end -}}

- {{ if $scope }}**{{ $scope }}:** {{ end }}{{ println (upperFirst (trim $commit.Subject)) }}

output:

- **inputs.opcua:** Accept non-standard OPC UA OK status by implementing a configurable workaround ([#10384](https://github.com/influxdata/telegraf/issues/10384))
- **outputs.timestream:** Fix batching logic with write records, introduce concurrent requests ([#8947](https://github.com/influxdata/telegraf/issues/8947))

The two output examples are missing the scope in the PR, and we would like it to have been the name of the plugin changed, the idea was for it to be a best guess to save time having to figure it out manually.

How this PR fixes the problem?

When the commit is being parsed in parseCommit, I added a call to git diff-tree --no-commit-id --name-only -r commit.Hash.Short to get the list of changed files and add it to the Commit struct.

Check lists

  • Test passed
  • Coding style (indentation, etc)

Thank you for taking a look.

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.

None yet

1 participant