From 9e8caa147fff88de6c68e737165b326b0a859606 Mon Sep 17 00:00:00 2001 From: BG Date: Mon, 30 Sep 2024 15:52:00 +0200 Subject: [PATCH] Switch to v2 attachment/content --- cloud/issue.go | 2 +- cloud/issue_test.go | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cloud/issue.go b/cloud/issue.go index 56d868ef..91e65074 100644 --- a/cloud/issue.go +++ b/cloud/issue.go @@ -653,7 +653,7 @@ func (s *IssueService) Get(ctx context.Context, issueID string, options *GetQuer // TODO Double check this method if this works as expected, is using the latest API and the response is complete // This double check effort is done for v2 - Remove this two lines if this is completed. func (s *IssueService) DownloadAttachment(ctx context.Context, attachmentID string) (*Response, error) { - apiEndpoint := fmt.Sprintf("secure/attachment/%s/", attachmentID) + apiEndpoint := fmt.Sprintf("rest/api/2/attachment/content/%s/", attachmentID) req, err := s.client.NewRequest(ctx, http.MethodGet, apiEndpoint, nil) if err != nil { return nil, err diff --git a/cloud/issue_test.go b/cloud/issue_test.go index a8ad6487..630aed77 100644 --- a/cloud/issue_test.go +++ b/cloud/issue_test.go @@ -401,9 +401,9 @@ func TestIssueService_DownloadAttachment(t *testing.T) { setup() defer teardown() - testMux.HandleFunc("/secure/attachment/", func(w http.ResponseWriter, r *http.Request) { + testMux.HandleFunc("/rest/api/2/attachment/content/", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, http.MethodGet) - testRequestURL(t, r, "/secure/attachment/10000/") + testRequestURL(t, r, "/rest/api/2/attachment/content/10000/") w.WriteHeader(http.StatusOK) w.Write([]byte(testAttachment)) @@ -436,9 +436,9 @@ func TestIssueService_DownloadAttachment_BadStatus(t *testing.T) { setup() defer teardown() - testMux.HandleFunc("/secure/attachment/", func(w http.ResponseWriter, r *http.Request) { + testMux.HandleFunc("/rest/api/2/attachment/content/", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, http.MethodGet) - testRequestURL(t, r, "/secure/attachment/10000/") + testRequestURL(t, r, "/rest/api/2/attachment/content/10000/") w.WriteHeader(http.StatusForbidden) }) @@ -487,7 +487,7 @@ func TestIssueService_PostAttachment(t *testing.T) { } } w.WriteHeader(status) - fmt.Fprint(w, `[{"self":"http://jira/jira/rest/api/2/attachment/228924","id":"228924","filename":"example.jpg","author":{"self":"http://jira/jira/rest/api/2/user?username=test","name":"test","emailAddress":"test@test.com","avatarUrls":{"16x16":"http://jira/jira/secure/useravatar?size=small&avatarId=10082","48x48":"http://jira/jira/secure/useravatar?avatarId=10082"},"displayName":"Tester","active":true},"created":"2016-05-24T00:25:17.000-0700","size":32280,"mimeType":"image/jpeg","content":"http://jira/jira/secure/attachment/228924/example.jpg","thumbnail":"http://jira/jira/secure/thumbnail/228924/_thumb_228924.png"}]`) + fmt.Fprint(w, `[{"self":"http://jira/jira/rest/api/2/attachment/228924","id":"228924","filename":"example.jpg","author":{"self":"http://jira/jira/rest/api/2/user?username=test","name":"test","emailAddress":"test@test.com","avatarUrls":{"16x16":"http://jira/jira/secure/useravatar?size=small&avatarId=10082","48x48":"http://jira/jira/secure/useravatar?avatarId=10082"},"displayName":"Tester","active":true},"created":"2016-05-24T00:25:17.000-0700","size":32280,"mimeType":"image/jpeg","content":"http://jira/jira/rest/api/2/attachment/content/228924/example.jpg","thumbnail":"http://jira/jira/secure/thumbnail/228924/_thumb_228924.png"}]`) }) reader := strings.NewReader(testAttachment) @@ -535,7 +535,7 @@ func TestIssueService_PostAttachment_NoFilename(t *testing.T) { testMethod(t, r, http.MethodPost) testRequestURL(t, r, "/rest/api/2/issue/10000/attachments") w.WriteHeader(http.StatusOK) - fmt.Fprint(w, `[{"self":"http://jira/jira/rest/api/2/attachment/228924","id":"228924","filename":"example.jpg","author":{"self":"http://jira/jira/rest/api/2/user?username=test","name":"test","emailAddress":"test@test.com","avatarUrls":{"16x16":"http://jira/jira/secure/useravatar?size=small&avatarId=10082","48x48":"http://jira/jira/secure/useravatar?avatarId=10082"},"displayName":"Tester","active":true},"created":"2016-05-24T00:25:17.000-0700","size":32280,"mimeType":"image/jpeg","content":"http://jira/jira/secure/attachment/228924/example.jpg","thumbnail":"http://jira/jira/secure/thumbnail/228924/_thumb_228924.png"}]`) + fmt.Fprint(w, `[{"self":"http://jira/jira/rest/api/2/attachment/228924","id":"228924","filename":"example.jpg","author":{"self":"http://jira/jira/rest/api/2/user?username=test","name":"test","emailAddress":"test@test.com","avatarUrls":{"16x16":"http://jira/jira/secure/useravatar?size=small&avatarId=10082","48x48":"http://jira/jira/secure/useravatar?avatarId=10082"},"displayName":"Tester","active":true},"created":"2016-05-24T00:25:17.000-0700","size":32280,"mimeType":"image/jpeg","content":"http://jira/jira/rest/api/2/attachment/content/228924/example.jpg","thumbnail":"http://jira/jira/secure/thumbnail/228924/_thumb_228924.png"}]`) }) reader := strings.NewReader(testAttachment) @@ -553,7 +553,7 @@ func TestIssueService_PostAttachment_NoAttachment(t *testing.T) { testMethod(t, r, http.MethodPost) testRequestURL(t, r, "/rest/api/2/issue/10000/attachments") w.WriteHeader(http.StatusOK) - fmt.Fprint(w, `[{"self":"http://jira/jira/rest/api/2/attachment/228924","id":"228924","filename":"example.jpg","author":{"self":"http://jira/jira/rest/api/2/user?username=test","name":"test","emailAddress":"test@test.com","avatarUrls":{"16x16":"http://jira/jira/secure/useravatar?size=small&avatarId=10082","48x48":"http://jira/jira/secure/useravatar?avatarId=10082"},"displayName":"Tester","active":true},"created":"2016-05-24T00:25:17.000-0700","size":32280,"mimeType":"image/jpeg","content":"http://jira/jira/secure/attachment/228924/example.jpg","thumbnail":"http://jira/jira/secure/thumbnail/228924/_thumb_228924.png"}]`) + fmt.Fprint(w, `[{"self":"http://jira/jira/rest/api/2/attachment/228924","id":"228924","filename":"example.jpg","author":{"self":"http://jira/jira/rest/api/2/user?username=test","name":"test","emailAddress":"test@test.com","avatarUrls":{"16x16":"http://jira/jira/secure/useravatar?size=small&avatarId=10082","48x48":"http://jira/jira/secure/useravatar?avatarId=10082"},"displayName":"Tester","active":true},"created":"2016-05-24T00:25:17.000-0700","size":32280,"mimeType":"image/jpeg","content":"http://jira/jira/rest/api/2/attachment/content/228924/example.jpg","thumbnail":"http://jira/jira/secure/thumbnail/228924/_thumb_228924.png"}]`) }) _, _, err := testClient.Issue.PostAttachment(context.Background(), "10000", nil, "attachment")