andygrunwald / go-jira

Go client library for Atlassian Jira
https://pkg.go.dev/github.com/andygrunwald/go-jira?tab=doc
MIT License
1.48k stars 471 forks source link

Support more api versions than just `2` #498

Open catouc opened 2 years ago

catouc commented 2 years ago

Is your feature request related to a problem? Please describe.

Our internal Jira server at work only responds to /jira/rest/api/latest/ but this library only supports /jira/rest/api/2/.

Describe the solution you'd like

I was thinking of having a field in the client like:

// A Client manages communication with the Jira API.
type Client struct {
    // HTTP client used to communicate with the API.
    client httpClient

    // Base URL for API requests.
    baseURL *url.URL
        apiVersion string

Then in the methods:

func (s *IssueService) GetWithContext(ctx context.Context, issueID string, options *GetQueryOptions) (*Issue, *Response, error) {
    apiEndpoint := fmt.Sprintf("rest/api/%s/issue/%s", s.apiVersion, issueID)

Then however we want to pass the configuration to the client to accept that apiVersion (in my local implementation I just let people overwrite the struct, but an option pattern is also worth considering I suppose, would break the existing interface somewhat with the baseURL)

Describe alternatives you've considered

Writing my own client and just using the types from this package is the only alternative possible right now.

Additional context

I'm happy to start a bit of work on this, refactoring the code to use that new value is easy enough, but the entire test suite seemed to be a bit more of a complex task - if someone is willing to walk me through that a bit I'm happy to write the change as well :) .

catouc commented 2 years ago

Added https://github.com/andygrunwald/go-jira/pull/499 to suggest an implementation that's similar to what I'm currently maintaining.

andygrunwald commented 2 years ago

@catouc Thanks! The new v2 will reflect this!