Closed janosh closed 3 years ago
pre-commit.ci actually doesn't have permission to do that at the moment -- but you can configure your repository to do this automatically:
I know. I have that setting enabled on some of my repos but it's a hassle to go into the settings UI for each new repo and press a bunch of buttons. With a config file, you put it in once and just copy it into new repos. Btw, I searched but couldn't find a way to enable that setting on new repos by default. Do you know of one?
I use this -- it was recently added to the api: https://github.com/asottile/set-delete-branch-on-merge
That's cool! 👍
there's a more efficient way to do it with the gql api but it works fine enough for me at the moment -- patches welcome!
More efficient in what sense? You wouldn't have to run repeatedly on all repos?
ah right now what it does is:
the reason it's for-each is because the bulk get does not tell us whether it is enabled or not
with gql we could do:
so right now it always sends ~100 requests for my repos, after it could be ~1 when nothing needs updating and ~11 when there need to be 10 things updated
I see. I might look into this tomorrow. Will share it if I put something together.
Btw, found this nice tool in case you weren't aware.
yeah I've played with the gql explorer -- according to github support this is approximately the query we'd need? I haven't tried it at all though:
{
viewer {
login
repositories(first: 100, affiliations: ORGANIZATION_MEMBER) {
nodes {
nameWithOwner
deleteBranchOnMerge
}
}
}
}
This might be start. Returns all my repos:
import requests
headers = {"Authorization": f"Bearer {os.environ['GH_TOKEN']}"}
def run_query(query: str) -> dict:
request = requests.post(
"https://api.github.com/graphql", json={"query": query}, headers=headers
)
if request.status_code == 200:
return request.json()
else:
raise Exception(f"{query=} failed with code {request.status_code}.")
repos_query = """
{
search(query: "user:janosh", type: REPOSITORY, first: 100) {
repositoryCount
edges {
node {
... on Repository {
name
}
}
}
}
}
"""
result = run_query(repos_query)
print(f"{result=}")
I put something together at janosh/auto-repo-config
that does exactly what I need but it no longer shares any code with asottile/set-delete-branch-on-merge
. Still happy to submit a PR if you're interested.
Would be great if pre-commit.ci automatically removed branches after they are merged/rebased.
If this seems too harsh for default behavior, maybe a config option?