From a334c1c1cc567c638928da1c0d90e3bccfefa847 Mon Sep 17 00:00:00 2001 From: Nikolai Emil Damm Date: Tue, 6 Jan 2026 11:30:41 +0100 Subject: [PATCH] feat: enhance Confluence link generation by utilizing base URL from API response Signed-off-by: Nikolai Emil Damm --- confluence/api.go | 12 +++++++++++- page/link.go | 10 +++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/confluence/api.go b/confluence/api.go index cb1aeae..312015e 100644 --- a/confluence/api.go +++ b/confluence/api.go @@ -61,6 +61,7 @@ type PageInfo struct { Links struct { Full string `json:"webui"` + Base string `json:"-"` // Not from JSON; populated from response _links.base } `json:"_links"` } @@ -193,6 +194,9 @@ func (api *API) FindPage( ) (*PageInfo, error) { result := struct { Results []PageInfo `json:"results"` + Links struct { + Base string `json:"base"` + } `json:"_links"` }{} payload := map[string]string{ @@ -222,7 +226,13 @@ func (api *API) FindPage( return nil, nil } - return &result.Results[0], nil + page := &result.Results[0] + // Populate the base URL from the response _links.base + if result.Links.Base != "" { + page.Links.Base = result.Links.Base + } + + return page, nil } func (api *API) CreateAttachment( diff --git a/page/link.go b/page/link.go index a1b270f..c5f8b1d 100644 --- a/page/link.go +++ b/page/link.go @@ -217,7 +217,15 @@ func getConfluenceLink( return "", nil } - tiny, err := GenerateTinyLink(api.BaseURL, page.ID) + // Prefer the base URL from the API response (_links.base) as it contains + // the canonical user-facing wiki URL (e.g., https://tenant.atlassian.net/wiki). + // Fall back to api.BaseURL if _links.base is not available. + baseURL := page.Links.Base + if baseURL == "" { + baseURL = api.BaseURL + } + + tiny, err := GenerateTinyLink(baseURL, page.ID) if err != nil { return "", karma.Format(err, "generate tiny link for page %s", page.ID) }