I have been investigating the graphql API call these days.
I have completed the tutorial of GitHub.
My question is that there must be some starting point for each graphql call.
in https://developer.github.com/v4/guides/using-the-explorer/
# the starting point is the object viewer
query {
viewer {
login
name
}
}
in https://developer.github.com/v4/guides/forming-calls/
# the starting point is the object repository
query {
repository(owner:"octocat", name:"Hello-World") {
issues(last:20, states:CLOSED) {
edges {
node {
title
url
labels(first:5) {
edges {
node {
name
}
}
}
}
}
}
}
}
What is the set of the possible objects which can be the starting point of a "query" or "mutation" in GraphQl call in Github ?
It seems the whole documentation of Github didn't mention this.
Go to Github GraphQL API explorer in here
Login and click the Docs button in the top-right corner
Click the Query or Mutation and it will show you all the available fields of the root Query and Mutation (i.e. starting point in your terminology) :
Related
My company is using the new GitHub projects beta and we're really enjoying the experience, but we're facing a problem and it is how to export the data from a specific view (or even all the data) with all the custom columns that we have.
The ideal solution for us is to get this same data as JSON using the API.
Using https://api.github.com/orgs/.../issues does not work because the issues does not have the custom columns that we create inside the project, and https://api.github.com/orgs/.../projects does not have the data of the issues.
Any idea or work-around to get this data easily using APIs?
After reading the feedback post on GitHub, it's not possible to do it with API, just GraphQL, at least for now.
So my problem was solved with this useful code.
To get the first 100 project from your organization and their ID:
query{
organization(login: "MY_ORG") {
projectsNext(first: 20) {
nodes {
id
title
}
}
}
}
To get the first 100 issues and drafts from a specific project:
{
node(id: "My_Project_ID") {
... on ProjectNext {
items(first: 100, after: null) {
edges {
cursor
}
nodes {
content {
... on Issue {
title
assignees(first: 1) {
nodes {
login
}
}
milestone {
title
}
labels(first: 5) {
nodes {
name
}
}
repository{
name
}
}
}
fieldValues(first: 15) {
nodes {
value
projectField {
name
settings
}
}
}
}
}
}
}
}
Those codes can be easily tested in THIS LINK
I'm creating a Multibranch Pipeline job with JobDSL , and I want to specify my github url , but it's not working.
The job which I created it display "https://github.com/jackson/multibranch-Pipeline.git" ,
not https://mycompanygithub.com/jackson/multibranch-Pipeline.git
Any idea how theses other parameters can be added in ?
or other solution
multibranchPipelineJob('Jenkins/Multibranch-Pipeline/GitHub_Basic') {
branchSources {
branchSource {
source {
github {
repositoryUrl('https://mycompanygithub.com')
credentialsId('mycredentialsid')
repoOwner('jackson')
repository('multibranch-Pipeline.git')
configuredByUrl(true)
}
}
}
}
}
Actually your configuration is correct, your are just missing one parameter: apiUri
// The server to connect to.
apiUri(String value)
Without it, it takes the default github.com as the base domain for the repository regardless of what is configured in the repositoryUrl parameter.
Try the following:
multibranchPipelineJob('Jenkins/Multibranch-Pipeline/GitHub_Basic') {
branchSources {
branchSource {
source {
github {
apiUri('https://mycompanygithub.com/api/v3')
repositoryUrl('https://mycompanygithub.com')
credentialsId('mycredentialsid')
repoOwner('jackson')
repository('multibranch-Pipeline.git')
configuredByUrl(true)
}
}
}
}
}
By the way you can see the full documentation of the Job DSL of this plugin at the following URL on your own Jenkins server:
YOUR_JENKINS_URL/plugin/job-dsl/api-viewer/index.html#method/javaposse.jobdsl.dsl.DslFactory.multibranchPipelineJob
I am trying to automate some stuff that will require to get the current images from a GitHub private repo.
Ideally, I'd iterate over the root directory and, for all images, get the URL for the RAW file.
For example:
For this image: https://github.com/Flow2015/logo/blob/master/flowImage01.jpg
I would like to get https://raw.githubusercontent.com/Flow2015/logo/master/flowImage01.jpg
If the URL is not available, I could get around with getting the binary content. However, I couldn't find a way to do that either.
As an example, this is basically how I am "finding" files that I want de details of.
{
repository(owner: "Flow2015", name: "logo") {
name
object(expression: "master:") {
... on Tree {
entries {
name
object{
... on Blob {
text
}
}
}
}
}
}
}
I understand that I could build the URL using Repo/branch/filename, I'm just trying to find a safe way if there is one.
In GitHub API v3 with repo and user authorization scopes, I can get my organizations with GET /user/orgs (https://developer.github.com/v3/orgs/#list-organizations-for-the-authenticated-user, with Octokit REST JS, octokit.orgs.listForAuthenticatedUser()) and for each organization, to get the repositories which I have access, GET /orgs/:org/repos (https://developer.github.com/v3/repos/#list-organization-repositories, with Octokit, octokit.repos.listForOrg({ org: orgs.data[i].login })).
However, with the same authentication scope (user and repos), running this Graphql query
query getOrgsRepos {
viewer {
organizations(first: 10) {
nodes {
repositories(first: 10) {
nodes {
name
}
}
}
}
}
}
Returns
{
"data": {
"viewer": {
"organizations": {
"nodes": []
}
}
}
}
Graphql Explorer result (https://developer.github.com/v4/explorer/), but running on my JS authed (user and repo scopes) app returns the same empty result
How to have the same behaviour with API v4, without having to give further permissions?
I just ran into this very issue today. Unfortunately, as of the timestamp indicated at the bottom of this answer, GitHub's GraphQL API is not on par with its REST API. The following query would only yield the viewer's public orgs i.e. what an unauthenticated session would show listed on their github.com profile under "Organizations".
query getOrgs {
viewer {
organizations(first: 100) {
totalCount
nodes {
name
}
}
}
}
And there is no equivalent of octokit.orgs.listForAuthenticatedUser() in their GraphQL schema which basically fetches the REST endpoint, /user/orgs, to list organizations for the authenticated user. From the docs:
/user/orgs only lists organizations that your authorization allows you
to operate on in some way (e.g., you can list teams with read:org
scope, you can publicize your organization membership with user scope,
etc.). Therefore, this API requires at least user or read:org scope.
OAuth requests with insufficient scope receive a 403 Forbidden
response.
In other words, with a personal access token with sufficient scopes, /user/orgs returns the same list shown on Your Organizations page. If you're authenticated using an OAuth access token, then the list is pretty much the same as shown under "Organization Access" on the user's Authorized OAuth Apps page for your OAuth app.
I think your query had a problem with missing the organization login:
query getOrgsRepos {
viewer {
organizations(first: 10) {
nodes {
login
repositories(first: 10) {
nodes {
name
}
}
}
}
}
}
I get responses with only those scopes.
I am making a very simple chrome extension that displays the number of contributions you did today on GitHub. How can i get that number?
You could use Github GraphQL API to request contributionsCollection with a date range :
query {
viewer {
contributionsCollection(from:"2020-05-05T00:00:00Z", to:"2020-05-05T00:00:00Z") {
contributionCalendar{
totalContributions
}
}
}
}
For a specific user:
query {
user(login:"krissemicolon") {
contributionsCollection(from:"2020-06-01T00:00:00Z", to:"2020-06-01T00:00:00Z") {
contributionCalendar{
totalContributions
}
}
}
}
If using graphql API is not an option you could also parse the calendar svg, checkout this