Add support for ghprb wrappers
Change-Id: Ia23cf5cd57a7db4492e2006257d0c62da3c95c07 Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
This commit is contained in:
parent
0b51780d2c
commit
3f3c3a1160
@ -2392,6 +2392,86 @@ def version_number(parser, xml_parent, data):
|
||||
convert_mapping_to_xml(version_number, data, mapping, fail_required=True)
|
||||
|
||||
|
||||
def github_pull_request(parser, xml_parent, data):
|
||||
"""yaml: github-pull-request
|
||||
Set GitHub commit status with custom context and message.
|
||||
Requires the Jenkins :jenkins-wiki:`GitHub Pull Request Builder Plugin
|
||||
<GitHub+pull+request+builder+plugin>`.
|
||||
|
||||
:arg bool show-matrix-status: Only post commit status of parent matrix job
|
||||
(default false)
|
||||
:arg str status-context: The context to include on PR status comments
|
||||
(default '')
|
||||
:arg str triggered-status: The status message to set when the build has
|
||||
been triggered (default '')
|
||||
:arg str started-status: The status message to set when the build has
|
||||
been started (default '')
|
||||
:arg str status-url: The status URL to set (default '')
|
||||
:arg bool status-add-test-results: Add test result one-liner to status
|
||||
message (default false)
|
||||
:arg list statuses: List of custom statuses on the commit for when a build
|
||||
is completed
|
||||
|
||||
:Status:
|
||||
* **message** (`str`) -- The message that is appended to a comment
|
||||
when a build finishes with the desired build status. If no status
|
||||
updates should be made when a build finishes with the indicated
|
||||
build status, use "--none--" to alert the trigger. (required)
|
||||
* **result** (`str`) -- Build result. Can be one of 'SUCCESS',
|
||||
'ERROR' or 'FAILURE'. (required)
|
||||
|
||||
Minimal Example:
|
||||
|
||||
.. literalinclude::
|
||||
/../../tests/wrappers/fixtures/github-pull-request-minimal.yaml
|
||||
:language: yaml
|
||||
|
||||
Full Example:
|
||||
|
||||
.. literalinclude::
|
||||
/../../tests/wrappers/fixtures/github-pull-request-full.yaml
|
||||
:language: yaml
|
||||
|
||||
"""
|
||||
ghprb = XML.SubElement(
|
||||
xml_parent, 'org.jenkinsci.plugins.ghprb.upstream.GhprbUpstreamStatus'
|
||||
)
|
||||
|
||||
mapping = [
|
||||
# option, xml name, default value
|
||||
("show-matrix-status", 'showMatrixStatus', False),
|
||||
("status-context", 'commitStatusContext', ''),
|
||||
("triggered-status", 'triggeredStatus', ''),
|
||||
("started-status", 'startedStatus', ''),
|
||||
("status-url", 'statusUrl', ''),
|
||||
("status-add-test-results", 'addTestResults', False)
|
||||
]
|
||||
convert_mapping_to_xml(ghprb, data, mapping, fail_required=True)
|
||||
|
||||
statuses = data.get('statuses', [])
|
||||
if statuses:
|
||||
status_mapping = [
|
||||
('message', 'message', None),
|
||||
('result', 'result', ''),
|
||||
]
|
||||
result_list = ['ERROR', 'SUCCESS', 'FAILURE']
|
||||
|
||||
completed_tag = XML.SubElement(ghprb, 'completedStatus')
|
||||
for status in statuses:
|
||||
result = status.get('result', '')
|
||||
if result not in result_list:
|
||||
raise JenkinsJobsException(
|
||||
"'result' must be one of: " + ', '.join(result_list))
|
||||
|
||||
result_tag = XML.SubElement(
|
||||
completed_tag,
|
||||
'org.jenkinsci.plugins.ghprb.extensions'
|
||||
'.comments.GhprbBuildResultMessage'
|
||||
)
|
||||
convert_mapping_to_xml(
|
||||
result_tag, status, status_mapping, fail_required=True)
|
||||
|
||||
|
||||
class Wrappers(jenkins_jobs.modules.base.Base):
|
||||
sequence = 80
|
||||
|
||||
|
23
tests/wrappers/fixtures/github-pull-request-full.xml
Normal file
23
tests/wrappers/fixtures/github-pull-request-full.xml
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<buildWrappers>
|
||||
<org.jenkinsci.plugins.ghprb.upstream.GhprbUpstreamStatus>
|
||||
<showMatrixStatus>true</showMatrixStatus>
|
||||
<commitStatusContext>my-build</commitStatusContext>
|
||||
<triggeredStatus>build was triggered</triggeredStatus>
|
||||
<startedStatus>build was started</startedStatus>
|
||||
<statusUrl>http://1.2.3.4</statusUrl>
|
||||
<addTestResults>true</addTestResults>
|
||||
<completedStatus>
|
||||
<org.jenkinsci.plugins.ghprb.extensions.comments.GhprbBuildResultMessage>
|
||||
<message>build has succeeded</message>
|
||||
<result>SUCCESS</result>
|
||||
</org.jenkinsci.plugins.ghprb.extensions.comments.GhprbBuildResultMessage>
|
||||
<org.jenkinsci.plugins.ghprb.extensions.comments.GhprbBuildResultMessage>
|
||||
<message>build has failed</message>
|
||||
<result>ERROR</result>
|
||||
</org.jenkinsci.plugins.ghprb.extensions.comments.GhprbBuildResultMessage>
|
||||
</completedStatus>
|
||||
</org.jenkinsci.plugins.ghprb.upstream.GhprbUpstreamStatus>
|
||||
</buildWrappers>
|
||||
</project>
|
13
tests/wrappers/fixtures/github-pull-request-full.yaml
Normal file
13
tests/wrappers/fixtures/github-pull-request-full.yaml
Normal file
@ -0,0 +1,13 @@
|
||||
wrappers:
|
||||
- github-pull-request:
|
||||
show-matrix-status: true
|
||||
status-context: "my-build"
|
||||
triggered-status: "build was triggered"
|
||||
started-status: "build was started"
|
||||
status-url: "http://1.2.3.4"
|
||||
status-add-test-results: true
|
||||
statuses:
|
||||
- message: "build has succeeded"
|
||||
result: SUCCESS
|
||||
- message: "build has failed"
|
||||
result: ERROR
|
13
tests/wrappers/fixtures/github-pull-request-minimal.xml
Normal file
13
tests/wrappers/fixtures/github-pull-request-minimal.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<buildWrappers>
|
||||
<org.jenkinsci.plugins.ghprb.upstream.GhprbUpstreamStatus>
|
||||
<showMatrixStatus>false</showMatrixStatus>
|
||||
<commitStatusContext/>
|
||||
<triggeredStatus/>
|
||||
<startedStatus/>
|
||||
<statusUrl/>
|
||||
<addTestResults>false</addTestResults>
|
||||
</org.jenkinsci.plugins.ghprb.upstream.GhprbUpstreamStatus>
|
||||
</buildWrappers>
|
||||
</project>
|
2
tests/wrappers/fixtures/github-pull-request-minimal.yaml
Normal file
2
tests/wrappers/fixtures/github-pull-request-minimal.yaml
Normal file
@ -0,0 +1,2 @@
|
||||
wrappers:
|
||||
- github-pull-request
|
Loading…
x
Reference in New Issue
Block a user