Giter Site home page Giter Site logo

Comments (6)

KonnorRogers avatar KonnorRogers commented on May 23, 2024 1

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"
      }
    }
  }
}

from bridgetown.

jaredcwhite avatar jaredcwhite commented on May 23, 2024

@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.

from bridgetown.

KonnorRogers avatar KonnorRogers commented on May 23, 2024

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.

from bridgetown.

jaredcwhite avatar jaredcwhite commented on May 23, 2024

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.

from bridgetown.

KonnorRogers avatar KonnorRogers commented on May 23, 2024

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.

from bridgetown.

jaredcwhite avatar jaredcwhite commented on May 23, 2024

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.

from bridgetown.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.