Skip to content
This repository has been archived by the owner on Apr 30, 2021. It is now read-only.

Look up all branches on repo by prefix. Days threshold for deleting stale branches #17

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

Conversation

bryanjebyrd
Copy link

This action suits my need well. The one addition I wanted to make is to be able to delete branches by prefix for all branches on the repo. This pull request has the capabilities to look up the branches by prefix, stage them for deletion, and then subsequently delete them.

@bryanjebyrd
Copy link
Author

Ideally, I think the suffix functionality can operate the same way as this rendition of the prefix functionality.

@bryanjebyrd bryanjebyrd changed the title Look up all branches by prefix and then delete them Look up all branches on repo by prefix. Days threshold for deleting stale branches Dec 20, 2020
@bryanjebyrd
Copy link
Author

I know I'm throwing a lot into this and I apologize. This is fun project for me and suits a use case I have in a mono-repo that I work in. Please let me know any feedback you have. I'm willing to change anything to get this out there in the marketplace. I'd love to be able to use this.

@@ -21,6 +21,12 @@ inputs:
suffix:
description: Additional suffix to append to every branch name
required: false
dry_run:
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think there is any need for this input. Why it was added?

Copy link
Author

Choose a reason for hiding this comment

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

This allows users of the action to see what branches it will delete without deleting it. This is meant to operate like most dry-run command line flags.

@@ -1,7 +1,7 @@
# Delete multiple branches GitHub Action

An action that deletes multiple branches from repository.
Optionally one can provide a `prefix` or `suffix` strings that would be appended or prepended to every branch name.
Copy link
Owner

Choose a reason for hiding this comment

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

Why removing prefix here?

Copy link
Author

Choose a reason for hiding this comment

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

The previous prefix was replaced with lookups against all the repo branches. The previous implementation users of the action had to explicitly know the branch name.

@@ -22,18 +32,57 @@ async function main() {
branchesToDelete.push(pull.data.head.ref)
}
}


if (prefix) {
Copy link
Owner

Choose a reason for hiding this comment

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

I don't know why you did it like this. Why if prefix here and not later, how it was done before? Why prefix is handled different than suffix?

Copy link
Author

Choose a reason for hiding this comment

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

We can make suffix be in parity with the prefix. Honestly, I have not experienced repos that name git branches with suffixes, so I left it be



if (prefix) {
const branchFunc = await client.paginate("GET /repos/{owner}/{repo}/branches", {
Copy link
Owner

Choose a reason for hiding this comment

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

Does octokit not have any standard function for getting branches? Do we need to insert the endpoint here?

Copy link
Author

Choose a reason for hiding this comment

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

I could not identify a function on octokit that operates like this. That was my first attempt but no luck

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants