#StackBounty: #javascript #graphql #github-api Get results from different arrays in one Promise.All with Github GraphQL API

Bounty: 50

I’m making a custom source plugin for Gatsby, that will get markdown files from a GitHub repository. The repository has individual files (blobs) and folders (trees), which in their turn also contain files. I need to get all files (including files inside folders) in one Promise.all, but I can’t figure out how to do that. I’ve managed to get individual files from the repository and I have a function which returns an array of files from the trees. But I don’t know how to combine them.

Here is my code. GraphQL queries to get repository, trees and files information:

const repositoryQuery = `
{
  viewer {
    repository(name: "repository-name") {
      object(expression: "master:") {
        ... on Tree {
          entries {
            name
            oid
            type
          }
        }
      }
    }
  }
}
`

const treeQuery = `
  query getTree($id: GitObjectID!) {
    viewer {
      repository(name: "repository-name") {
        object(oid: $id) {
          ... on Tree {
            entries {
              name
              oid
              type
            }
          }
        }
      }
    }
  }
`

const fileQuery = `
  query getFile($id: GitObjectID!) {
    viewer {
      repository(name: "repository-name") {
        object(oid: $id) {
          ... on Blob {
            text
          }
        }
      }
    }
  }
` 

And the functions themselves:

const data = await client.request(repositoryQuery)

const getTree = async entry => {
  const data = await client.request(treeQuery, { id: entry.oid })
  const array = await data.viewer.repository.object.entries
  return array
}

const getFile = async entry => {
  const data = await client.request(fileQuery, { id: entry.oid })
  const result = await data.viewer.repository.object
  return result
}

const files = await Promise.all(
  data.viewer.repository.object.entries
    .filter(entry => entry.type !== "tree")
    .map(entry => {
      return (
        getFile(entry)
        .then(file => {
          return {
            data: file.text
          }
        })
      )
    }
  )
)

files.forEach(file =>
  createNode({...})
)

How can I update const files so that it will:

  1. Run getFile(), if entry.type !== "tree"
  2. If entry.type is tree, get an array of files inside the tree with getTree() and then run getFile() for each file.
  3. Combine all results in one array, so that I can apply to them createNode.

I would really appreciate your help.


Get this bounty!!!

#StackBounty: #jenkins #github #github-api How to update build status for PR merge commit

Bounty: 50

We can use this command to update the build status for a commit:

curl "https://api.github.com/repos/chnlmeter/$repo_name/statuses/$GIT_COMMIT?access_token=$github_build_status_token" 
  -H "Content-Type: application/json" 
  -X POST 
  -d "$(cat <<EOF
{"state": "success","context": "continuous-integration/jenkins", "description": "Jenkins", "target_url": "$BUILD_URL"}
EOF
)"

my question is – I want to create a temporary merge commit between the integration branch and feature branch and then test that commit – after a merge takes place, not before.
Is there a way for github to create that merge commit and then notify jenkins of that commit? And then I want to update the build status for that commit so it shows up on the pull request page on Github.


enter image description here

The above image will show up on the PR page, but it only pertains to the feature branch commit, not a merge commit which would result of the actual merge of the two branches.


Get this bounty!!!

#StackBounty: #r #travis-ci #github-api #httr Authenticate at Github via Travis-CI using httr as well as locally (local works, remote d…

Bounty: 200

I have an Rmd file that uses httr to access the Github-API. Locally, I can authenticate with Github just fine if I run the following in the R console before rendering the Rmd:

myapp <- oauth_app("APP", key = "xyz", secret = "pqr")
github_token <- oauth2.0_token(oauth_endpoints("github"), myapp)

The key and secret were created at Github, and exist in my workspace when I render, so github_token is picked up and I can access the Github-API without hitting the access limit when rendering locally.

Now, the same Rmd is also built automatically at Travis-CI and then deployed to gh-pages when I push the master branch. I have this working w/o authentification but that limits my Githhub-API request limit to 60/hr and I need the higher limit one gets with authentification. So for this I have a personal access token (PAT) also set up in Github; the page where one sets the PAT says “Personal access tokens function like ordinary OAuth access tokens. They can be used instead of a password for Git over HTTPS, or can be used to authenticate to the API over Basic Authentication”.

Here is part of my Rmd where I try to detect if the rendering is local or remote and get the appropriate token. However, when this is run at Travis-CI, the token doesn’t appear to be recognized, so I don’t think I’m using it correctly.

# Figure out the build location, and get the needed token
at_home <- FALSE
at_TCI <- FALSE
token_found <- FALSE
token_OK <- FALSE # not used now/yet

# Check to see if we are at TRAVIS-CI
# This next variable is in the Travis build environment & is a character string
token_value <- Sys.getenv("TRAVIS_CI") 
if (token_value != "") {
  token_found <- TRUE
  at_TCI <- TRUE
}

# Check to see if we are on the local/home machine
# This token is generated interactively via "Web Application Flow",
# and is deposited in the local workspace
# See developer.github.com/apps/building-oauth-apps/authorizing-oauth-apps/#web-application-flow
# This token has classes 'Token2.0', 'Token', 'R6' <Token2.0>
if (!at_TCI) {
  token_found <- exists("github_token")
  if (token_found) {
    token_value <- github_token
    at_home <- TRUE
  }
}

# See where we stand and act accordingly
if (!token_found) {
  message("Could not retrieve token - GET calls will be rate-limited by Github")
  # TEMPORARY: just use a few lines for faster testing & not blasting GH limits
  DF <- DF[1:5,]
}
if (token_found) {
  set_config(config(token = token_value)) # applies to all GET requests below
}

I don’t think the set_config call is working correctly when I’m at Travis-CI, because I get an error that seems to come from a GET call that occurs later (it’s really hard to troubleshoot on T-CI, but the Rmd works fine locally). Here is a sample GET call that fails remotely after running the snippet above, but works locally:

repoOK[i] <- identical(status_code(GET(DF$repo[i])), 200L)

where DF$repo[i] is a URL.

I’m new to httr and the Github-API, but I’ve spent a lot of time experimenting with incantations found here on SO, and with the Github documentation, but so far no success with the remote build. Hence I call upon the mercies of the SO community!

EDIT: GH repo with full code. See the SO_Q branch for the code that goes with this question.


Get this bounty!!!