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

Support for "main" branch in automations #82

Closed
jaredcwhite opened this issue Jun 29, 2020 · 6 comments
Closed

Support for "main" branch in automations #82

jaredcwhite opened this issue Jun 29, 2020 · 6 comments
Labels
high priority This should get addressed as soon as possible. process Improve the development process for the repo question Further information is requested

Comments

@jaredcwhite
Copy link
Member

Related to #77, currently we're assuming that if a branch name isn't specified for an automation via a GitHub URL, then look for the automation script in the master branch. Fair assumption.

But we really should be looking at the default branch whatever it is, whether it's main or something else. I'm not sure if there's an easily-accessible API of some kind to ask GH what the default branch name is for a given repo. Barring that, I'm thinking we'll just need to try both main and master and pick the first one that doesn't 404. If you have ideas for how to do this cleanly, please let me know!

@jaredcwhite jaredcwhite added this to the 0.16.0 "Crystal Springs" milestone Jun 29, 2020
@jaredcwhite jaredcwhite added process Improve the development process for the repo question Further information is requested labels Jun 29, 2020
@KonnorRogers
Copy link
Member

Yes its possible. After some digging into the Github API I found where to query for a "default_branch".

V3 Rest API:

https://developer.github.com/v3/repos/#get-a-repository

V4 GraphQL API

query DefaultBranchQuery {
  repository(owner: "bridgetownrb", name: "bridgetown"){
    defaultBranchRef {
      name
    }
  }
}

will return the following data:

{
  "data": {
    "repository": {
      "defaultBranchRef": {
        "name": "main"
      }
    }
  }
}

@jaredcwhite
Copy link
Member Author

@ParamagicDev Cool! As I think about this, I've run into rate limits in the past using the GH API without a specific key, but that was when pinging the API multiple times a minute from the same machine. So I'm guessing a one-off now and then should be fine, but we'll want to gracefully handle any error conditions.

@KonnorRogers
Copy link
Member

KonnorRogers commented Jul 2, 2020

https://developer.github.com/v3/#rate-limiting You are correct. An unauthenticated user is allowed 60 requests / hour under the REST API. And a similar number under the graphQL api.

There is another way to check the default branch using the git cli, but it would require cloning the repository.

I guess we could silently pull down the repository into a tempdir, check the default branch, then request the automation. Although at that point, you could just run the automation directly in the cloned repo....

Edit: the more I think about it, the more I like the idea of pulling a repo down in the background because if a user requests a different branch, you could simply do git checkout otherwise, you're already on the default branch.

@jaredcwhite
Copy link
Member Author

Hmm 🤔

I know we're already manually doing Git checkouts in some of the automations…but that feels a little heavyweight to me to go with for a default approach.

@KonnorRogers
Copy link
Member

KonnorRogers commented Jul 8, 2020

Maybe if no master branch is found, raise an error and prompt the user to provide a branch?

EDIT: Actually, if no master branch is found, we could rescue the error and then we could prompt the user to provide a branch on the command line so they don't have to retype the command.

@jaredcwhite
Copy link
Member Author

At the risk of overcomplicating things, I suggest we could try the following:

  1. Use the GitHub API to get the default branch name
  2. In the event that API call fails, hardcode master and try that
  3. If that doesn't work, then we could ask for the branch name

Honestly I'm fine even with dropping option 3… just prompt them to paste a branch-specific URL instead.

@jaredcwhite jaredcwhite added the high priority This should get addressed as soon as possible. label Jul 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
high priority This should get addressed as soon as possible. process Improve the development process for the repo question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants