diff --git a/jenkins_jobs/modules/project_multibranch.py b/jenkins_jobs/modules/project_multibranch.py index 14ebd6166..dbf5f6db2 100644 --- a/jenkins_jobs/modules/project_multibranch.py +++ b/jenkins_jobs/modules/project_multibranch.py @@ -1194,6 +1194,7 @@ def github_scm(xml_parent, data): if data.get("build-strategies", None): build_strategies(xml_parent, data) + add_github_checks_traits(traits, data) add_notification_context_trait(traits, data) add_filter_by_name_wildcard_behaviors(traits, data) @@ -1925,3 +1926,59 @@ def add_notification_context_trait(traits, data): nc_trait_suffix.text = str(nc_suffix).lower() else: nc_trait_suffix.text = nc_suffix + + +def add_github_checks_traits(traits, data): + """Enable and configure the usage of GitHub Checks API + + Requires the :jenkins-plugins:`Github Checks ` plugin. + + :arg dict status-checks: + + * **name** (str): The text of the context label for GitHub Checks entry + * **skip** (bool): Skips publishing Checks (optional, default false) + * **skip-branch-source-notifications** (bool): Disables the default + option of publishing statuses through Status API + (optional, default false) + * **publish-unstable-as-neutral** (bool): Publishes UNSTABLE builds + as neutral (not failed) checks + (optional, default false) + * **suppress-log-output** (bool): Suppresses sending build logs to GitHub + (optional, default false) + * **suppress-progress-updates** (bool): Suppresses updating build progress + (optional, default false) + * **verbose-logs** (bool): Enables sending build console logs to GitHub + (optional, default false) + """ + if data.get("status-checks", None): + status_checks_section = data["status-checks"] + if status_checks_section.get("verbose-logs", None): + sct = XML.SubElement( + traits, + "io.jenkins.plugins.checks.github.config.GitHubSCMSourceChecksTrait", + {"plugin": "github-checks"}, + ) + sct_mapping = [("verbose-logs", "verboseConsoleLog", "false")] + helpers.convert_mapping_to_xml( + sct, status_checks_section, sct_mapping, fail_required=True + ) + + status_check_trait = XML.SubElement( + traits, + "io.jenkins.plugins.checks.github.status.GitHubSCMSourceStatusChecksTrait", + {"plugin": "github-checks"}, + ) + status_check_trait_mapping = [ + ("skip", "skip", "false"), + ("skip-branch-source-notifications", "skipNotifications", "false"), + ("publish-unstable-as-neutral", "unstableBuildNeutral", "false"), + ("name", "name", "Jenkins"), + ("suppress-log-output", "suppressLogs", "false"), + ("suppress-progress-updates", "skipProgressUpdates", "false"), + ] + helpers.convert_mapping_to_xml( + status_check_trait, + status_checks_section, + status_check_trait_mapping, + fail_required=True, + ) diff --git a/tests/multibranch/fixtures/scm_github_full.xml b/tests/multibranch/fixtures/scm_github_full.xml index e5877120c..cf021043b 100644 --- a/tests/multibranch/fixtures/scm_github_full.xml +++ b/tests/multibranch/fixtures/scm_github_full.xml @@ -76,6 +76,17 @@ bar* *qaz + + true + + + true + true + true + my-checks + true + true + jenkins.example.com/my_context false diff --git a/tests/multibranch/fixtures/scm_github_full.yaml b/tests/multibranch/fixtures/scm_github_full.yaml index 3b7277ff0..391f93976 100644 --- a/tests/multibranch/fixtures/scm_github_full.yaml +++ b/tests/multibranch/fixtures/scm_github_full.yaml @@ -35,6 +35,14 @@ scm: notification-context: label: 'jenkins.example.com/my_context' suffix: false + status-checks: + name: my-checks + skip: true + skip-branch-source-notifications: true + publish-unstable-as-neutral: true + suppress-log-output: true + suppress-progress-updates: true + verbose-logs: true property-strategies: all-branches: - suppress-scm-triggering: true