2

I am using below query to create repo:

   gh api -i graphql -f query='
   mutation {
   createRepository(input: {name: "gh-create-test", visibility: PRIVATE, ownerId: "ID"}) {
    repository {
      url
    }
  }
}
'

THe repo gets created successfully but without admin rights whereas when I create repo from GITHUB UI the repo has admin rights. Can anyone please help what's the issue in this query?

Stack_IQ
  • 438
  • 5
  • 20

1 Answers1

2

I just created one, Make sure you are getting the id first and pass it to the createRepository

query{
  repositoryOwner(login:"yourLoginId"){
    id
    login
    repositories(first:1) {
      edges {
        node {
          id
        }
      }
    }
  }
}

and create a repository by passing the ownerid

mutation {
   createRepository(input: {name: "gh-create-test", visibility: PRIVATE, ownerId: "idobtainedabove"}) {
    repository {
      url
    }
  }
}
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
  • “yourloginid” what Id is expected here? Github login ? – Stack_IQ Aug 04 '21 at 14:58
  • Error: ``` { "data": { "createRepository": null }, "errors": [ { "type": "FORBIDDEN", "path": [ "createRepository" ], "extensions": { "saml_failure": false }, "locations": [ { "line": 3, "column": 3 } ], "message": "Resource not accessible by integration" ``` – Stack_IQ Aug 05 '21 at 04:37
  • But i can create repos from GUI with proper permissions why this is not working with cli? – Stack_IQ Aug 05 '21 at 04:39
  • It works fine for me. Are you trying to do this within an organization? – Sajeetharan Aug 05 '21 at 04:45
  • Yes I am trying for an org – Stack_IQ Aug 05 '21 at 04:58
  • Do I need to define my PATanywhere? – Stack_IQ Aug 05 '21 at 04:58
  • No need to define – Sajeetharan Aug 05 '21 at 05:02
  • I exported PAT: export GITHUB_TOKEN="MyPAT" and get below error: "errors": [ { "type": "NOT_FOUND", "path": [ "createRepository" ], "locations": [ { "line": 3, "column": 4 } ], "message": "Could not resolve to RepositoryOwner node with the global id of "nodeid" – Stack_IQ Aug 05 '21 at 05:03
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/235643/discussion-between-stack-iq-and-sajeetharan). – Stack_IQ Aug 05 '21 at 05:03
  • It worked finally after enabling SSO. Thanks for your time..:) – Stack_IQ Aug 05 '21 at 05:56
  • There are two obligatory fields to create a repo: `name` and `visibility`. Regarding visibility, case matters. However `ownerId` is not mandatory because of missing `!` in the [docs](https://docs.github.com/en/graphql/reference/input-objects#createrepositoryinput) – Timo Nov 29 '22 at 17:12