#7 add client and helper methods for interacting with https://pagure.io
Merged by mikeb. Opened by mikeb.
mikeb/c3i-library pagure-client  into  master

The PagureClient class allows retrieving information about a PR, updating
the status of a PR, and adding comments. The class can be instantiated
directly, or used via the helper methods, which grab parameters from
environment variables.

This code was taken with minimal modification from the PagureClient
written by Yuxiang Zhu for the WaiverDB project.

@rayson Would you mind taking a look? Note that I'm happy to reconsider the API structure and naming, just wanted to get something out there that we could iterate on. Comments appreciated!

Hi @mikeb,
Thanks for inviting me. I am also thinking about the naming and structure of this part, will follow up before this Thursday.

BTW, I am also looking at a unit test library (https://github.com/jenkinsci/JenkinsPipelineUnit) for Jenkins pipeline and shared library. It seems to be nice and hopefully it can help us test our shared library and pipeline scripts.

I noticed functions in this file are basically copied from our WaiverDB Jenkinsfile.
Those functions reference environment variables from the job run, and assumes the credentials ID like this line.
I think we probably should remove any project-specific code from this file, and make it usable for more generic purpose.

One option is to only add the PagureClient.groovy to the library, then we can sit down and design a new API for Jenkinsfiles. What do you think?

Some thoughts on the API usage:

// get information of a pull-request:
def prInfo = pagure('some-project', auth).pr(no).get()
// set PR status
pagure('some-project', auth).pr(no).flag(username: 'c3i-jenkins', uid: 'c3i-premerge', comment: 'Build success',  percent: 100, url: someUrl)
// comment a PR
pagure('some-project', auth).pr(no).comment('Build failed.')
// poll master branch
pagure.repo('some-repo').pollBranch('master')
// poll pull-requests
pagure.repo('some-repo').pollPullRequests()

@rayson I like some ideas there. Let me update the PR to be a minimal implementation without the project-specific code, and we can then iterate on API enhancements in subsequent PRs.

Btw, I'm very interested in looking at JenkinsPipelineUnit for testing this library!

rebased onto c73f3f4e419fe77e9ea83f3a2dd3d8b1cfdbabc4

Where is steps definition?

Where is steps definition?

@cqi It is defined implicitly during the execution of a pipeline. See https://jenkins.io/doc/book/pipeline/shared-libraries/#accessing-steps for more information.

Pull-Request has been merged by mikeb