import com.sonymusic.Utils

def call(Map args){
    def params = Utils.validateParams('githubGetCommitPrs', args, [
        repo: [type: String, required: true],
        commitSha: [type: String, required: true],
        owner: [type: String, required: false, defaultValue: 'theorchard'],
    ])

    withCredentials([string(credentialsId: 'orchardci-webhook-token', variable: 'GITHUB_TOKEN')]) {
        def response = sh(script: """
            set +x
            curl -X GET -H "Authorization: token \${GITHUB_TOKEN}" \
            -H "Accept: application/vnd.github+json" \
            -H "X-GitHub-Api-Version: 2022-11-28" \
            https://api.github.com/repos/${params.owner}/${params.repo}/commits/${params.commitSha}/pulls
        """, returnStdout: true)
        return readJSON(text: response)
    }
}
