1

I have an application that records the names of some GitHub repositories in database. Take the following 3 repos for example.

  1. https://github.com/zhangkun-Jser/react-experience
  2. https://github.com/zhangkun-Jser/vue-plug
  3. https://github.com/hsluoyz/casbin

But the issue is the repos I recorded may be renamed. For example, the above three repos have been respectively renamed to:

  1. https://github.com/zhangkun-Jser/react-kit
  2. https://github.com/zhangkun-Jser/FE-plugs
  3. https://github.com/casbin/casbin

I want to write some code to actively update any old repo names to new repo names in my database. For example, update zhangkun-Jser/react-experience to zhangkun-Jser/react-kit.

I know I can use GitHub V3 API to get the repository info for every repo and then get the new name. But this requires to send a request for every repo. My question is if there is any method to get the new names for a list of repos in one request?

Note: The repos can be from different owners, like in the example.

I tried to use the GraphQL API v4 but I didn't know how to get the info of a list of repos. And the V4 API seems not to recognize the old names. For example, if I send the following request:

{
  repository(owner: "zhangkun-Jser" name: "react-experience") {
    name
    id
  }
}

The response is:

{
  "data": {
    "repository": null
  },
  "errors": [
    {
      "message": "Could not resolve to a Repository with the name 'react-experience'.",
      "type": "NOT_FOUND",
      "path": [
        "repository"
      ],
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ]
    }
  ]
}

Anyone can help? Thanks.

hsluoyz
  • 2,739
  • 5
  • 35
  • 59

1 Answers1

1

You could store the Node ID of the Repository and look up the Node by ID:

query { 
  repository (owner:"osowskit", name:"about") { 
    id
  },
  node(id:"MDEwOlJlcG9zaXRvcnk1NjE2NzA2OQ") {
  ... on Repository {
      id,
      name,
      nameWithOwner
    }
  }
}
osowskit
  • 5,904
  • 2
  • 29
  • 38
  • Let's say I have stored the node ids of multiple repos (from multiple users). How to query their latest names in one GraphQL request? If I have to use multiple requests, there is no difference with GitHub V3 API. – hsluoyz Jan 08 '18 at 12:50
  • I apologize for missing that part of the question. The long-term strategy is to store node IDs instead of repo names to avoid detecting name changes. However, you can look up multiple sets of data by using an [Alias](http://graphql.org/learn/queries/#aliases). ``` repo1: repository (...) {}, repo2: repository (...) {} ``` – osowskit Jan 08 '18 at 19:24