From 752f033c440f32e17e2468e652d807dabce358dd Mon Sep 17 00:00:00 2001 From: Corentin Flr <10946971+cogk@users.noreply.github.com> Date: Wed, 10 Apr 2024 16:17:58 +0200 Subject: [PATCH] feat(app_source): Add gitlab_access_token field --- press/press/doctype/app_source/app_source.json | 7 +++++++ press/press/doctype/app_source/app_source.py | 11 +++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/press/press/doctype/app_source/app_source.json b/press/press/doctype/app_source/app_source.json index f6fbc6cbd70..f73c11bcc76 100644 --- a/press/press/doctype/app_source/app_source.json +++ b/press/press/doctype/app_source/app_source.json @@ -22,6 +22,7 @@ "github_installation_id", "uninstalled", "gitlab_project_id", + "gitlab_access_token", "section_break_12", "versions", "github_section", @@ -83,6 +84,12 @@ "fieldtype": "Data", "label": "GitLab Project ID" }, + { + "depends_on": "eval:doc.gitlab_project_id", + "fieldname": "gitlab_access_token", + "fieldtype": "Password", + "label": "GitLab Access Token" + }, { "fieldname": "data_3", "fieldtype": "Column Break" diff --git a/press/press/doctype/app_source/app_source.py b/press/press/doctype/app_source/app_source.py index bbe973656e2..0203bb460f4 100644 --- a/press/press/doctype/app_source/app_source.py +++ b/press/press/doctype/app_source/app_source.py @@ -102,8 +102,15 @@ def create_gitlab_release(self, force=False): url = f"{repo_url.scheme}://{repo_url.netloc}{api_path}" headers = {} - # if gitlab_token := frappe.get_value("Press Settings", None, "gitlab_access_token"): - # headers["Authorization"] = f"Bearer {gitlab_token}" + + gitlab_token = "" + if self.get("gitlab_access_token"): + gitlab_token = gitlab_token or self.get_password("gitlab_access_token") + # gitlab_token = gitlab_token or frappe.db.get_single_value("Press Settings", None, "gitlab_access_token") + + if gitlab_token: + headers["Authorization"] = f"Bearer {gitlab_token}" + res = requests.get(url, headers=headers).json() frappe.db.set_value(