Skip to content

GHPullRequestFileDetail seems to be returning wrong/unexpected sha #486

@LenGillespie

Description

@LenGillespie

Given this groovy snippet:

#!/usr/bin/env groovy

import org.kohsuke.github.*

@GrabResolver(name = 'jenkins-api', root = 'http://central.maven.org/maven2')
@Grab("org.kohsuke:github-api:1.95")

String repo = "<repo>"
String apiToken = "<token>"
String organization = "<org>"
int prId = <id>

def getRepository = { repoName ->
    GitHub github = GitHub.connectUsingOAuth(apiToken)
    return github.getRepository("${organization}/${repoName}")
}

def getPullRequestChanges = { repoName, id ->
    GHPullRequest pullRequest = getRepository(repoName).getPullRequest(id)
    return pullRequest.listFiles().collect()
}

List<GHPullRequestFileDetail> changes = getPullRequestChanges(repo, prId)

changes.each {
    println "Commit: https://github.com/${organization}/${repo}/commit/${it.sha}"
}

I'm expecting to get the SHA where the file was changed on the branch but that doesn't seem to be the case. I can see the 6 files changed on the PR but when I navigate to any of their associated SHAs, I get a 404.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions