Add support of gitlab-ci
Review Request #14211 — Created Oct. 24, 2024 and updated
Add support of gitlab-ci
Added integration and saw that it calls the pipeline on gitlab.
Summary | ID |
---|---|
7cc427b0261e253904db5854bb251d80e73695bc |
Description | From | Last Updated | ||
---|---|---|---|---|
Also it would be a good idea to provide a gitlab component for patching like this. templates/ref.yml spec: --- .reviewboard: … |
|
|||
're' imported but unused Column: 1 Error code: F401 |
![]() |
|||
're' imported but unused Column: 1 Error code: F401 |
![]() |
|||
line break before binary operator Column: 13 Error code: W503 |
![]() |
|||
line break before binary operator Column: 13 Error code: W503 |
![]() |
|||
line break before binary operator Column: 13 Error code: W503 |
![]() |
|||
There are no open issues |
- Summary:
-
WIP Add support of gitlab-ciAdd support of gitlab-ci
- Description:
-
~ WIP Add support of gitlab-ci
~ Add support of gitlab-ci
- Testing Done:
-
+ Added integration and saw that it calls the pipeline on gitlab.
- Commits:
-
Summary ID 0cd1f7e13ffea73695adcbf8fd0ed540fd28de27 1bc87e573cddb172e5f295ce2aa7fc8be7bae10c
Checks run (1 failed, 1 succeeded)
flake8
- Commits:
-
Summary ID 1bc87e573cddb172e5f295ce2aa7fc8be7bae10c 1bc87e573cddb172e5f295ce2aa7fc8be7bae10c
- Commits:
-
Summary ID 1bc87e573cddb172e5f295ce2aa7fc8be7bae10c 0307c1bd8d6cee04d6390640cde4dc21258db4d5
Checks run (2 succeeded)
-
-
The best way to notify RB from gitlab would be a webook from gitlab to RB. I wrote a tiny wsgi application that get's "pipeline event" [1] for the project/group that calls rbt. A better approach would be to include the ability to RB itself without that wrapper script.
#!/usr/bin/python import json import logging import uwsgi import subprocess log = logging.getLogger("gitlab") logging.basicConfig( format="%(asctime)s %(levelname)s: %(message)s", level="INFO" ) def health(): return None def get_state(state): if state == "pending": return ("build queued...", "pending") if state == "passed": return ("build succeeded.", "done-success") if state == "running": return ("build started...", "pending") if state == "canceling": return ("canceling build...", "pending") if state == "canceled": return ("build canceled", "error") return ("build failed", "error") def process_rbtools(v, c, token): url = c.get("url") url_text = "See pipeline" description, state = get_state(c.get("detailed_status")) cmd = [ "rbt", "status-update", "set", "--url", url, "--url-text", url_text, "-r", v.get("REVIEWBOARD_REVIEW_ID"), "-s", v.get("REVIEWBOARD_STATUS_UPDATE_ID"), "--server", v.get("REVIEWBOARD_SERVER"), "--api-token", token, "--state", state, "--description", description, "--disable-cookie-storage", "--disable-cache-storage", ] log.info(cmd) subprocess.check_call(cmd) return uwsgi.SPOOL_OK def process_pipeline(c, token): if c is not None: v = c.get("variables") if v is not None: v = {item["key"]: item["value"] for item in v} if "REVIEWBOARD_SERVER" in v: return process_rbtools(v, c, token) return uwsgi.SPOOL_OK def process_data(data): try: c = json.loads(data.get("body")) except (TypeError, ValueError) as e: log.info("Broken json: {0}".format(e)) return uwsgi.SPOOL_OK # log.debug(json.dumps(c, indent=4, sort_keys=True)) if c.get("object_kind") == "pipeline" and "object_attributes" in c: return process_pipeline(c.get("object_attributes"), data.get(b"token")) return uwsgi.SPOOL_OK def process_spooler(data): try: return process_data(data) except BaseException: log.exception("Cannot process data") return uwsgi.SPOOL_RETRY def application(environ, start_response): result = [] headers = [("Content-Type", "text/plain")] request_body = [] try: request_body_size = environ.get("CONTENT_LENGTH", 0) if request_body_size: request_body = environ["wsgi.input"].read(int(request_body_size)) except ValueError as e: log.warn("Cannot read body: {0}".format(e)) headers.append(("Content-Length", str(len(result)))) start_response("400 Bad Request", headers) return result status = "200 OK" if len(request_body) > 0 and "HTTP_X_GITLAB_TOKEN" in environ: uwsgi.spool( { b"body": request_body, b"token": environ["HTTP_X_GITLAB_TOKEN"].encode("utf-8"), } ) else: healthResult = health() if healthResult is None: status = "204 No Content" else: status = "503 Service Unavailable" result = [healthResult.encode("utf-8")] headers.append(("Content-Length", str(len(result)))) start_response(status, headers) return result uwsgi.spooler = process_spooler
[1] https://docs.gitlab.com/user/project/integrations/webhook_events/#pipeline-events
-
Also it would be a good idea to provide a gitlab component for patching like this.
templates/ref.yml
spec: --- .reviewboard: reviewboard_before_script: - | if [ "$REVIEWBOARD_SERVER" != "" ]; then apk add rbtools git rbt patch --server ${REVIEWBOARD_SERVER} --diff-revision ${REVIEWBOARD_DIFF_REVISION} ${REVIEWBOARD_REVIEW_ID} fi
templates/global_before_script.yml
spec: --- include: - component: https://github.com/reviewboard/rbintegrations/ref@main before_script: - !reference [.reviewboard, reviewboard_before_script]
customer .gitlab-ci.yml
include: - component: https://github.com/reviewboard/rbintegrations/ref@main first-job: script: - echo Hello
- Commits:
-
Summary ID 0307c1bd8d6cee04d6390640cde4dc21258db4d5 a1f1316f27e283b2f1819dee845250d15da76f4a
Checks run (2 succeeded)
- Commits:
-
Summary ID a1f1316f27e283b2f1819dee845250d15da76f4a 1b8d10f23e35d52f6d142e845c14b9b6625f4c30
Checks run (2 succeeded)
- Commits:
-
Summary ID 1b8d10f23e35d52f6d142e845c14b9b6625f4c30 07a041231afc9a85712e81b73539e7c56347cc9f
Checks run (2 succeeded)
- Commits:
-
Summary ID 07a041231afc9a85712e81b73539e7c56347cc9f fac64c4771f050aa05b5535b46f27e2526ab0c62 - Diff:
-
Revision 8 (+1054)
- Commits:
-
Summary ID fac64c4771f050aa05b5535b46f27e2526ab0c62 7cc427b0261e253904db5854bb251d80e73695bc - Diff:
-
Revision 9 (+1054)