feat: enhance Confluence link generation by utilizing base URL from API response

Signed-off-by: Nikolai Emil Damm <ndam@tv2.dk>
This commit is contained in:
Nikolai Emil Damm 2026-01-06 11:30:41 +01:00 committed by Manuel Rüger
parent bb4d4e2dab
commit a334c1c1cc
2 changed files with 20 additions and 2 deletions

View File

@ -61,6 +61,7 @@ type PageInfo struct {
Links struct { Links struct {
Full string `json:"webui"` Full string `json:"webui"`
Base string `json:"-"` // Not from JSON; populated from response _links.base
} `json:"_links"` } `json:"_links"`
} }
@ -193,6 +194,9 @@ func (api *API) FindPage(
) (*PageInfo, error) { ) (*PageInfo, error) {
result := struct { result := struct {
Results []PageInfo `json:"results"` Results []PageInfo `json:"results"`
Links struct {
Base string `json:"base"`
} `json:"_links"`
}{} }{}
payload := map[string]string{ payload := map[string]string{
@ -222,7 +226,13 @@ func (api *API) FindPage(
return nil, nil 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( func (api *API) CreateAttachment(

View File

@ -217,7 +217,15 @@ func getConfluenceLink(
return "", nil 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 { if err != nil {
return "", karma.Format(err, "generate tiny link for page %s", page.ID) return "", karma.Format(err, "generate tiny link for page %s", page.ID)
} }