I want to downgrade my GitHub account to the free plan. GitHub warns me that I have one private repository that uses GitHub Pages - a feature that the free plan doesn't support. So I want to find this repo to see if it is problematic if it becomes public.
I can't find any way to even list my repos that use Github Pages, let alone the ones that are private.
Is there a way to do this?
Yes, simple via GraphQL API, with or without GraphQL API Explorer, (don't forget personal access token scope if using without the explorer,) if you don't have very much private repos.
Use query:
query {
viewer {
repositories (first:100, privacy: PRIVATE) {
nodes {
name
deployments (first: 1) {
nodes {
environment
}
}
}
}
}
}
Example result:
{
"data": {
"viewer": {
"repositories": {
"nodes": [
{
"name": "repo-without-pages",
"deployments": {
"nodes": []
}
},
{
"name": "repo-with-pages",
"deployments": {
"nodes": [
{
"environment": "github-pages"
}
]
}
}
]
}
}
}
}
Typically the only possible environment is github-pages. If you have more, change the above query.
Note GitHub GraphQL API has a limit: Values of first and last must be within 1-100. If you have more than 100, use:
repositories (first:100, privacy: PRIVATE) {
pageInfo {
endCursor
}
and after getting endCursor:
repositories (first:100, privacy: PRIVATE, after:"endCursorValue==") {
pageInfo {
endCursor
}
to paginate.
Related
I'm cross-posting the question from here.
I’m interested in knowing whether it’s possible to fetch all the statuses for all the contexts for a given reference using the GQL API.
The query that I’m currently doing is the following:
{
repository(owner: "owner", name: "name") {
pullRequests(headRefName: "head-ref", last: 1) {
nodes {
id
commits(first: 10) {
nodes {
commit {
oid
status {
contexts {
context
createdAt
id
description
state
}
}
}
}
}
}
}
}
}
This query returns a single status for each status context, and those are the last ones for each:
{
"data": {
"repository": {
"pullRequests": {
"nodes": [
{
"id": "some-id",
"commits": {
"nodes": [
{
"commit": {
"oid": "some-oid",
"status": {
"contexts": [
{
"context": "context-1",
"createdAt": "2021-07-06T21:28:26Z",
"id": "***",
"description": "Your tests passed!",
"state": "SUCCESS"
},
{
"context": "context-2",
"createdAt": "2021-07-06T21:25:26Z",
"id": "***",
"description": "Your tests passed!",
"state": "SUCCESS"
},
]
}
}
}
]
}
}
]
}
}
}
}
On the other hand, if I use the REST API with this query:
curl -i -u se7entyse7en:$(cat token) https://api.github.com/repos/owner/name/commits/some-oid/statuses
where some-oid is the corresponding retrieved with the GQL API, the output contains ALL the statuses. In particular, I can see all the statuses of context-1 and context-2 that happened before those that are returned by the GQL API.
It seems a limitation of the GQL schema given that StatusContext is a node instead of being a list of nodes. Basically, I expect StatusContext to be of type [Status!]! where Status represents a single status for the given context.
Am I missing something? Is this something expected to be changed in the future? Is the REST API the only option?
Thanks.
I opened a support ticket and this is the expected behavior indeed, there are no plans for changing it. The only solution is to use the REST API.
The link to the community forum is this one.
I'm trying to list collaborators for all repos in an organization. My query looks like this.
query($login: String!, $cursor: String) {
organization(login: $login) {
url
login
repositories(first: 100, after: $cursor) {
pageInfo {
endCursor
hasNextPage
}
nodes {
name
collaborators(affiliation: OUTSIDE, first: 100) {
edges {
permission
}
nodes {
url
login
name
email
company
}
}
}
}
}
}
This works fine in the GraphQL Explorer. No permissions errors as my user has the necessary permissions.
However if I try to do this from the GraphQL API endpoint directly, I get:
[
{
"type": "FORBIDDEN",
"path": [
"organization",
"repositories",
"nodes",
0,
"collaborators"
],
"locations": [
{
"line": 18,
"column": 21
}
],
"message": "Must have push access to view repository collaborators."
},
I have given my personal access token all possible scopes to debug, the issue persists.
Since my user is org admin and can list all collaborators from the GraphQL Explorer, I would expect this to work.
I have given my personal access token all possible scopes to debug, the issue persists.
Nevertheless, if you don't have push/write access to those repositories, you would get that error message, irrespective of the scopes you gave to your token.
(as illustrated here)
See also isaacs/github issue 444 for confirmation.
I'm developing a Github webhook that gets notifications on issue updates.
These issues are associated to one of more Github Project Boards
The body payload shows this information related to the updated issue:
Nothing about issue association with project boards. Is there a way to get this information?
You can use GraphQL API to get that information using projectCards under the Issue object :
{
repository(name: "caipy-dashboard", owner: "bertrandmartel") {
issue(number: 26) {
title
projectCards {
nodes {
createdAt
column {
name
}
project {
name
body
}
}
}
}
}
}
Output :
{
"data": {
"repository": {
"issue": {
"title": "fix dead path in startover",
"projectCards": {
"nodes": [
{
"createdAt": "2017-08-28T05:47:49Z",
"column": {
"name": "Done"
},
"project": {
"name": "Startover",
"body": "Show epg / caipy events + startover modes"
}
}
]
}
}
}
}
}
Try it in the explorer
I have a Project in Github with some columns, and I'm trying to locate cards (Issues) that are in the closed state.
With GraphQL I'm having trouble constructing a query that can filter the cards. Currently I have this query:
query {
organization(login:"org") {
project(number:3) {
columns(first:1){
nodes{
id,
name,
cards(first:1){
nodes{
content {
... on Issue {
url,
state
}
}
}
}
}
}
}
}
}
This returns the result:
{
"data": {
"organization": {
"project": {
"columns": {
"nodes": [
{
"id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"name": "On Deck",
"cards": {
"nodes": [
{
"content": {
"url": "https://github.com/org/repo/issues/606",
"state": "OPEN"
}
}
]
}
}
]
}
}
}
}
}
What I have gathered thus far is that the "Project Cards" are "UNION" objects in GraphQL and I have no idea how to add filters to these unions.
Any suggestions?
Thank you!
I asked the same question on the GitHub Community forum. An admin wrote back:
The way that the GraphQL API is currently built, no, you can't filter project cards on the state of the issue that they're representing using only the query language. You would have to query all cards in the column and then filter it yourself.
Github API documentation give instructions to filter repositories by topics.
Is there a way to use the API to get the topics from a specific repo?
You can do this with the Github GraphQL API
Query:
{
repository(owner: "twbs", name: "bootstrap") {
repositoryTopics(first: 10) {
edges {
node {
topic {
name
}
}
}
}
}
}
This will return the first 10 topics and the name for each as shown below.
Response:
{
"data": {
"repository": {
"repositoryTopics": {
"edges": [
{
"node": {
"topic": {
"name": "css"
}
}
},
{
"node": {
"topic": {
"name": "bootstrap"
}
}
},
{
"node": {
"topic": {
"name": "javascript"
}
}
},
{
"node": {
"topic": {
"name": "html"
}
}
}
]
}
}
}
}
Test it out in the GitHub GraphQL Explorer
You can do this easily with Github API (it's currently in "preview mode"):
curl -H "Accept: application/vnd.github.mercy-preview+json" https://api.github.com/repos/twbs/bootstrap/topics
{
"names": [
"css",
"bootstrap",
"javascript",
"html",
"jekyll-site",
"scss",
"css-framework",
"sass"
]
}
You need to include extra header Accept: application/vnd.github.mercy-preview+json.
There is one "but", since it's in "preview mode" it's not supported for production use (please read "Note" and "Warning" sections in link below).
See also:
https://docs.github.com/en/rest/reference/repos#get-a-repository
I don't know that there is a way to just get the topics for a repository, but if you do a get for a repository, the repository json object that is returned will have a topics property that is an array of that repositories topics.
At the top of that page of documentation, you will notice that in order to have the topics returned you will need to add a specific header in your GET request: "Accept":"application/vnd.github.mercy-preview+json"
Hope this helps!
I faced similar problem, so I made a node module that only require one line of code to do that which is
var github_topics = require('github-topics');
var topics = github_topics.gettopics('url_of_repo');
for example
var topics = github_topics.gettopics('https://github.com/Aniket965/blog');
It will return array of topics of that github repository , link to that node module is NPM
I added the fetch with Accept Headers:
fetch("https://api.github.com/users/lucksp/repos",
{
method: "GET",
headers: {
Accept: "application/vnd.github.mercy-preview+json"
}
})