Skip to content

Conversation

@max-frank
Copy link
Contributor

@max-frank max-frank commented Nov 6, 2024

WHAT

SSIA

WHY

Details

By switching to using --name-status instead of --name-only for retrieving the diff it becomes possible to differentiate between the 4 cases.

An example output with all 4 cases would look like this

D       deleted_file.txt
M       modified_file.txt
R100    renamed_file_org.txt      renamed_file_new.txt 
A       added_file.txt 

With this its easy to parse the output

  • deleted: D
  • modified: M
  • renamed: R<\d\d\d> (the number is the sameness percentage between the new and old file)
  • new: A

For M and A we can keep the same logic that already exists. For D we simply create a tree node with sha set to null, this indicates a deletion for the API. In the context of the API R is simply a delete for the old file path and a add for the new one.

@CLAassistant
Copy link

CLAassistant commented Nov 6, 2024

CLA assistant check
All committers have signed the CLA.

@max-frank max-frank force-pushed the add-delete-and-moved-support branch from 5c13f6c to 2757e65 Compare November 6, 2024 11:25
@max-frank
Copy link
Contributor Author

max-frank commented Nov 6, 2024

Ideally i'd like to add some tests, but I dont know typescript well enough to implement those given that everything seems to be just un exported functions. Also no idea what the typescript way of mocking/testing the filesystem + git would be 🤔

for now I've tested it similar to the test workflow locally (in my private org where i have an app already setup) and everything seems to work

updating the test workflow to show case the rename + delete support would require doing either 2 rounds of commits in the workflow or permanently committing test files so i skipped that for now

@max-frank max-frank marked this pull request as ready for review November 6, 2024 11:35
@max-frank max-frank marked this pull request as draft November 6, 2024 11:37
@max-frank max-frank force-pushed the add-delete-and-moved-support branch from 2757e65 to 66d85ee Compare November 7, 2024 00:37
@max-frank max-frank force-pushed the add-delete-and-moved-support branch from 66d85ee to 6c3f896 Compare November 7, 2024 01:33
@max-frank max-frank marked this pull request as ready for review November 7, 2024 01:37
@max-frank
Copy link
Contributor Author

@abannachGrafana does this look like a reasonable approach to solving #55 to you?

@abannachGrafana
Copy link
Contributor

@max-frank I apologize for being a terrible maintainer and not catching this sooner. I've got another PR to simplify this action #57 to use the graphql api. Which has deletions added, but haven't worked on renames just yet. I'll see if I can add that as well.

Your approach looks correct though. Renames are essentially delete old file add new file same contents. I'm including it in my PR.

@abannachGrafana
Copy link
Contributor

Example usage

- name: Commit changes
    uses: grafana/github-api-commit-action@077642073699d6dd9e9c42a9f69ce517fabf79d2 # v0.3.0
    with:
      commit-message: "<commit-message>" # Commit message defaults to "Commit performed by grafana/github-api-commit-action"
      create-branch-on-remote: true # Whether to create the branch on the remote if it doesn't exist already: Defaults to false
      stage-all-files: true # Whether to additionally stage any changed files in the checkout. Defaults to false
      token: ${{ secrets.GITHUB_TOKEN }} # Token you want to authenticate with, must have write permission to repo

For now I'll close this PR since I've removed any typescript/node code from it. Thanks for the help!

@max-frank max-frank deleted the add-delete-and-moved-support branch February 12, 2025 04:42
@max-frank
Copy link
Contributor Author

@max-frank I apologize for being a terrible maintainer and not catching this sooner. I've got another PR to simplify this action #57 to use the graphql api. Which has deletions added, but haven't worked on renames just yet. I'll see if I can add that as well.

Your approach looks correct though. Renames are essentially delete old file add new file same contents. I'm including it in my PR.

No worries, thanks for your open source work ;)

I'll switch from my fork to your new version using graphql and will report back should I run into any issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants