From 090b5472c50b66dfc3779b17d5e9a92d21b4a1a6 Mon Sep 17 00:00:00 2001 From: elias-AD <88844419+elias-AD@users.noreply.github.com> Date: Wed, 27 Nov 2024 23:19:05 -0500 Subject: [PATCH 1/3] support_cloud_URLs Instead of relying only on *.atlassian.net, modify the input to be cloudUrl so different flavours of Confluence URLs can be used (including *.jira.com). --- README.md | 4 ++-- src/main.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4d5ec33..da13a22 100644 --- a/README.md +++ b/README.md @@ -27,13 +27,13 @@ jobs: Uses basic auth for the rest api. -- `cloud`: The ID can be found by looking at your confluence domain: `https://.atlassian.net/...` +- `cloudUrl`: The URL (without https://) of your confluence instance. E.g: `acme.atlassian.net/...` or `acme.jira.com` - `user`: The user that generated the access token - `token`: You can generate the token [here](https://id.atlassian.com/manage-profile/security/api-tokens). Link to [Docs](https://confluence.atlassian.com/cloud/api-tokens-938839638.html) -- `to`: The page ID can be found by simply navigating to the page where you want the content to be postet to and looke at the url. It will look something like this: `https://.atlassian.net/wiki/spaces//pages//` +- `to`: The page ID can be found by simply navigating to the page where you want the content to be postet to and looke at the url. It will look something like this: `https://<cloudUrl>/wiki/spaces/<space>/pages/<page-id>/<title>` ### Using secrets diff --git a/src/main.py b/src/main.py index 7e85f12..226c097 100644 --- a/src/main.py +++ b/src/main.py @@ -15,7 +15,7 @@ if not workspace: exit(1) envs: Dict[str, str] = {} -for key in ['from', 'to', 'cloud', 'user', 'token']: +for key in ['from', 'to', 'cloudUrl', 'user', 'token']: value = environ.get(f'INPUT_{key.upper()}') if not value: print(f'Missing value for {key}') @@ -25,7 +25,7 @@ for key in ['from', 'to', 'cloud', 'user', 'token']: with open(join(workspace, envs['from'])) as f: md = f.read() -url = f"https://{envs['cloud']}.atlassian.net/wiki/rest/api/content/{envs['to']}" +url = f"https://{envs['cloudUrl']}/wiki/rest/api/content/{envs['to']}" current = requests.get(url, auth=(envs['user'], envs['token'])).json() From a59824adbbd7f625e06a32f6b0b905ceb8df8960 Mon Sep 17 00:00:00 2001 From: elias-AD <88844419+elias-AD@users.noreply.github.com> Date: Thu, 28 Nov 2024 09:29:50 -0500 Subject: [PATCH 2/3] modified `cloud` to support both subdomains (*.atlassian.net) or actual domains (e.g. ame.jira.com) instead of introducing a potential breaking change, this will support both cases --- README.md | 8 ++++++-- src/main.py | 10 ++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index da13a22..93f6bc8 100644 --- a/README.md +++ b/README.md @@ -27,13 +27,17 @@ jobs: Uses basic auth for the rest api. -- `cloudUrl`: The URL (without https://) of your confluence instance. E.g: `acme.atlassian.net/...` or `acme.jira.com` +- `cloud`: Can be either: + - A subdomain (e.g., `acme` for Atlassian hosted instances) + - A full URL (e.g., `https://mycompany.com` for self-hosted instances) - `user`: The user that generated the access token - `token`: You can generate the token [here](https://id.atlassian.com/manage-profile/security/api-tokens). Link to [Docs](https://confluence.atlassian.com/cloud/api-tokens-938839638.html) -- `to`: The page ID can be found by simply navigating to the page where you want the content to be postet to and looke at the url. It will look something like this: `https://<cloudUrl>/wiki/spaces/<space>/pages/<page-id>/<title>` +- `to`: The page ID can be found by simply navigating to the page where you want the content to be posted to and look at the url. It will look something like this: + - For Atlassian hosted: `https://<subdomain>.atlassian.net/wiki/spaces/<space>/pages/<page-id>/<title>` + - For self-hosted: `https://<your-url>/wiki/spaces/<space>/pages/<page-id>/<title>` ### Using secrets diff --git a/src/main.py b/src/main.py index 226c097..f8415d9 100644 --- a/src/main.py +++ b/src/main.py @@ -15,7 +15,7 @@ if not workspace: exit(1) envs: Dict[str, str] = {} -for key in ['from', 'to', 'cloudUrl', 'user', 'token']: +for key in ['from', 'to', 'cloud', 'user', 'token']: value = environ.get(f'INPUT_{key.upper()}') if not value: print(f'Missing value for {key}') @@ -25,7 +25,13 @@ for key in ['from', 'to', 'cloudUrl', 'user', 'token']: with open(join(workspace, envs['from'])) as f: md = f.read() -url = f"https://{envs['cloudUrl']}/wiki/rest/api/content/{envs['to']}" +base_url = envs['cloud'] +if '://' in base_url: # It's a full URL + # Remove trailing slash if present + base_url = base_url.rstrip('/') + url = f"{base_url}/wiki/rest/api/content/{envs['to']}" +else: # It's a subdomain + url = f"https://{base_url}.atlassian.net/wiki/rest/api/content/{envs['to']}" current = requests.get(url, auth=(envs['user'], envs['token'])).json() From e43940725bc9962bd3bdd5ecf4572f63294db77b Mon Sep 17 00:00:00 2001 From: elias-AD <88844419+elias-AD@users.noreply.github.com> Date: Thu, 28 Nov 2024 09:34:59 -0500 Subject: [PATCH 3/3] update readme to make it more clear --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 93f6bc8..edd5fbc 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ jobs: Uses basic auth for the rest api. - `cloud`: Can be either: - - A subdomain (e.g., `acme` for Atlassian hosted instances) + - A subdomain (`acme` for Atlassian hosted instances (e.g. `https://acme.atlassian.net`)) - A full URL (e.g., `https://mycompany.com` for self-hosted instances) - `user`: The user that generated the access token