Skip to content

Commit

Permalink
Merge branch 'master' into github-actions-testing
Browse files Browse the repository at this point in the history
* master:
  feat(IssueService): allow empty JQL (#268)
  style: Fix staticcheck (static analysis) errors for this library (#283)
  feat(project): Add workflow to greet new contributors (#288)
  feat(project): Add cronjob to check for stale issues (#287)
  feat(issues): Add GetEditMeta on issue
  • Loading branch information
andygrunwald committed May 2, 2020
2 parents 4f03fa8 + 4b91cf2 commit c65a982
Show file tree
Hide file tree
Showing 23 changed files with 288 additions and 113 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/greetings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Greetings
on: [pull_request, issues]

jobs:
greeting:
runs-on: ubuntu-latest
steps:
- uses: actions/first-interaction@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
issue-message: 'Hi! Thank you for taking the time to create your first issue! Really cool to see you here for the first time. Please give us a bit of time to review it.'
pr-message: 'Great! Thank you for taking the time to create your first pull request. It is always a pleasure to see people like you who spent time contributing. Please give us a bit of time to review it!'
19 changes: 19 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: "Close stale issues"
on:
schedule:
- cron: "0 4 * * *"

jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: >
This issue has been automatically marked as stale because it has not had
recent activity in the last 60 days. It will be closed in 7 days if no further activity occurs.
Thank you for your contributions.
days-before-stale: 60
days-before-close: 7
stale-issue-label: stale
24 changes: 12 additions & 12 deletions authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ func (s *AuthenticationService) AcquireSessionCookie(username, password string)
}

if err != nil {
return false, fmt.Errorf("Auth at JIRA instance failed (HTTP(S) request). %s", err)
return false, fmt.Errorf("auth at Jira instance failed (HTTP(S) request). %s", err)
}
if resp != nil && resp.StatusCode != 200 {
return false, fmt.Errorf("Auth at JIRA instance failed (HTTP(S) request). Status code: %d", resp.StatusCode)
return false, fmt.Errorf("auth at Jira instance failed (HTTP(S) request). Status code: %d", resp.StatusCode)
}

s.client.session = session
Expand Down Expand Up @@ -127,15 +127,15 @@ func (s *AuthenticationService) Logout() error {
apiEndpoint := "rest/auth/1/session"
req, err := s.client.NewRequest("DELETE", apiEndpoint, nil)
if err != nil {
return fmt.Errorf("Creating the request to log the user out failed : %s", err)
return fmt.Errorf("creating the request to log the user out failed : %s", err)
}

resp, err := s.client.Do(req, nil)
if err != nil {
return fmt.Errorf("Error sending the logout request: %s", err)
return fmt.Errorf("error sending the logout request: %s", err)
}
if resp.StatusCode != 204 {
return fmt.Errorf("The logout was unsuccessful with status %d", resp.StatusCode)
return fmt.Errorf("the logout was unsuccessful with status %d", resp.StatusCode)
}

// If logout successful, delete session
Expand All @@ -150,37 +150,37 @@ func (s *AuthenticationService) Logout() error {
// JIRA API docs: https://docs.atlassian.com/jira/REST/latest/#auth/1/session
func (s *AuthenticationService) GetCurrentUser() (*Session, error) {
if s == nil {
return nil, fmt.Errorf("AUthenticaiton Service is not instantiated")
return nil, fmt.Errorf("authenticaiton Service is not instantiated")
}
if s.authType != authTypeSession || s.client.session == nil {
return nil, fmt.Errorf("No user is authenticated yet")
return nil, fmt.Errorf("no user is authenticated yet")
}

apiEndpoint := "rest/auth/1/session"
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
if err != nil {
return nil, fmt.Errorf("Could not create request for getting user info : %s", err)
return nil, fmt.Errorf("could not create request for getting user info : %s", err)
}

resp, err := s.client.Do(req, nil)
if err != nil {
return nil, fmt.Errorf("Error sending request to get user info : %s", err)
return nil, fmt.Errorf("error sending request to get user info : %s", err)
}
if resp.StatusCode != 200 {
return nil, fmt.Errorf("Getting user info failed with status : %d", resp.StatusCode)
return nil, fmt.Errorf("getting user info failed with status : %d", resp.StatusCode)
}

defer resp.Body.Close()
ret := new(Session)
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("Couldn't read body from the response : %s", err)
return nil, fmt.Errorf("couldn't read body from the response : %s", err)
}

err = json.Unmarshal(data, &ret)

if err != nil {
return nil, fmt.Errorf("Could not unmarshall received user info : %s", err)
return nil, fmt.Errorf("could not unmarshall received user info : %s", err)
}

return ret, nil
Expand Down
24 changes: 12 additions & 12 deletions authentication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ func TestAuthenticationService_AcquireSessionCookie_Failure(t *testing.T) {
if err != nil {
t.Errorf("Error in read body: %s", err)
}
if bytes.Index(b, []byte(`"username":"foo"`)) < 0 {
if !bytes.Contains(b, []byte(`"username":"foo"`)) {
t.Error("No username found")
}
if bytes.Index(b, []byte(`"password":"bar"`)) < 0 {
if !bytes.Contains(b, []byte(`"password":"bar"`)) {
t.Error("No password found")
}

Expand Down Expand Up @@ -53,10 +53,10 @@ func TestAuthenticationService_AcquireSessionCookie_Success(t *testing.T) {
if err != nil {
t.Errorf("Error in read body: %s", err)
}
if bytes.Index(b, []byte(`"username":"foo"`)) < 0 {
if !bytes.Contains(b, []byte(`"username":"foo"`)) {
t.Error("No username found")
}
if bytes.Index(b, []byte(`"password":"bar"`)) < 0 {
if !bytes.Contains(b, []byte(`"password":"bar"`)) {
t.Error("No password found")
}

Expand Down Expand Up @@ -144,10 +144,10 @@ func TestAithenticationService_GetUserInfo_AccessForbidden_Fail(t *testing.T) {
if err != nil {
t.Errorf("Error in read body: %s", err)
}
if bytes.Index(b, []byte(`"username":"foo"`)) < 0 {
if !bytes.Contains(b, []byte(`"username":"foo"`)) {
t.Error("No username found")
}
if bytes.Index(b, []byte(`"password":"bar"`)) < 0 {
if !bytes.Contains(b, []byte(`"password":"bar"`)) {
t.Error("No password found")
}

Expand Down Expand Up @@ -182,10 +182,10 @@ func TestAuthenticationService_GetUserInfo_NonOkStatusCode_Fail(t *testing.T) {
if err != nil {
t.Errorf("Error in read body: %s", err)
}
if bytes.Index(b, []byte(`"username":"foo"`)) < 0 {
if !bytes.Contains(b, []byte(`"username":"foo"`)) {
t.Error("No username found")
}
if bytes.Index(b, []byte(`"password":"bar"`)) < 0 {
if !bytes.Contains(b, []byte(`"password":"bar"`)) {
t.Error("No password found")
}

Expand Down Expand Up @@ -238,10 +238,10 @@ func TestAuthenticationService_GetUserInfo_Success(t *testing.T) {
if err != nil {
t.Errorf("Error in read body: %s", err)
}
if bytes.Index(b, []byte(`"username":"foo"`)) < 0 {
if !bytes.Contains(b, []byte(`"username":"foo"`)) {
t.Error("No username found")
}
if bytes.Index(b, []byte(`"password":"bar"`)) < 0 {
if !bytes.Contains(b, []byte(`"password":"bar"`)) {
t.Error("No password found")
}

Expand Down Expand Up @@ -280,10 +280,10 @@ func TestAuthenticationService_Logout_Success(t *testing.T) {
if err != nil {
t.Errorf("Error in read body: %s", err)
}
if bytes.Index(b, []byte(`"username":"foo"`)) < 0 {
if !bytes.Contains(b, []byte(`"username":"foo"`)) {
t.Error("No username found")
}
if bytes.Index(b, []byte(`"password":"bar"`)) < 0 {
if !bytes.Contains(b, []byte(`"password":"bar"`)) {
t.Error("No password found")
}

Expand Down
4 changes: 2 additions & 2 deletions board_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,13 @@ func TestBoardService_GetAllSprintsWithOptions(t *testing.T) {
})

sprints, _, err := testClient.Board.GetAllSprintsWithOptions(123, &GetAllSprintsOptions{State: "active,future"})

if err != nil {
t.Errorf("Got error: %v", err)
}

if sprints == nil {
t.Error("Expected sprint list. Got nil.")
return
}

if len(sprints.Values) != 1 {
Expand All @@ -235,13 +235,13 @@ func TestBoardService_GetBoardConfigoration(t *testing.T) {
})

boardConfiguration, _, err := testClient.Board.GetBoardConfiguration(35)

if err != nil {
t.Errorf("Got error: %v", err)
}

if boardConfiguration == nil {
t.Error("Expected boardConfiguration. Got nil.")
return
}

if len(boardConfiguration.ColumnConfig.Columns) != 6 {
Expand Down
4 changes: 2 additions & 2 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ func NewJiraError(resp *Response, httpError error) error {
if strings.HasPrefix(contentType, "application/json") {
err = json.Unmarshal(body, &jerr)
if err != nil {
httpError = errors.Wrap(errors.New("Could not parse JSON"), httpError.Error())
httpError = errors.Wrap(errors.New("could not parse JSON"), httpError.Error())
return errors.Wrap(err, httpError.Error())
}
} else {
if httpError == nil {
return fmt.Errorf("Got Response Status %s:%s", resp.Status, string(body))
return fmt.Errorf("got response status %s:%s", resp.Status, string(body))
}
return errors.Wrap(httpError, fmt.Sprintf("%s: %s", resp.Status, string(body)))
}
Expand Down
4 changes: 2 additions & 2 deletions error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ func TestError_BadJSON(t *testing.T) {
err := NewJiraError(resp, errors.New("Original http error"))
msg := err.Error()

if !strings.Contains(msg, "Could not parse JSON") {
t.Errorf("Expected the 'Could not parse JSON' error message: Got\n%s\n", msg)
if !strings.Contains(msg, "could not parse JSON") {
t.Errorf("Expected the 'could not parse JSON' error message: Got\n%s\n", msg)
}
}

Expand Down
2 changes: 1 addition & 1 deletion filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestFilterService_Get(t *testing.T) {
testMux.HandleFunc(testAPIEndpoint, func(writer http.ResponseWriter, request *http.Request) {
testMethod(t, request, "GET")
testRequestURL(t, request, testAPIEndpoint)
fmt.Fprintf(writer, string(raw))
fmt.Fprint(writer, string(raw))
})

filter, _, err := testClient.Filter.Get(10000)
Expand Down
41 changes: 24 additions & 17 deletions issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/http"
"net/url"
"reflect"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -192,7 +193,7 @@ func (i *IssueFields) UnmarshalJSON(data []byte) error {
options := strings.Split(tagDetail, ",")

if len(options) == 0 {
return fmt.Errorf("No tags options found for %s", field.Name)
return fmt.Errorf("no tags options found for %s", field.Name)
}
// the first one is the json tag
key := options[0]
Expand Down Expand Up @@ -757,11 +758,11 @@ func (s *IssueService) Create(issue *Issue) (*Issue, *Response, error) {
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, resp, fmt.Errorf("Could not read the returned data")
return nil, resp, fmt.Errorf("could not read the returned data")
}
err = json.Unmarshal(data, responseIssue)
if err != nil {
return nil, resp, fmt.Errorf("Could not unmarshall the data into struct")
return nil, resp, fmt.Errorf("could not unmarshall the data into struct")
}
return responseIssue, resp, nil
}
Expand Down Expand Up @@ -939,7 +940,7 @@ func (s *IssueService) UpdateWorklogRecord(issueID, worklogID string, record *Wo
//
// JIRA API docs: https://docs.atlassian.com/jira/REST/latest/#api/2/issueLink
func (s *IssueService) AddLink(issueLink *IssueLink) (*Response, error) {
apiEndpoint := fmt.Sprintf("rest/api/2/issueLink")
apiEndpoint := "rest/api/2/issueLink"
req, err := s.client.NewRequest("POST", apiEndpoint, issueLink)
if err != nil {
return nil, err
Expand All @@ -957,29 +958,35 @@ func (s *IssueService) AddLink(issueLink *IssueLink) (*Response, error) {
//
// JIRA API docs: https://developer.atlassian.com/jiradev/jira-apis/jira-rest-apis/jira-rest-api-tutorials/jira-rest-api-example-query-issues
func (s *IssueService) Search(jql string, options *SearchOptions) ([]Issue, *Response, error) {
var u string
if options == nil {
u = fmt.Sprintf("rest/api/2/search?jql=%s", url.QueryEscape(jql))
} else {
u = "rest/api/2/search?jql=" + url.QueryEscape(jql)
u := url.URL{
Path: "rest/api/2/search",
}
uv := url.Values{}
if jql != "" {
uv.Add("jql", url.QueryEscape(jql))
}

if options != nil {
if options.StartAt != 0 {
u += fmt.Sprintf("&startAt=%d", options.StartAt)
uv.Add("startAt", strconv.Itoa(options.StartAt))
}
if options.MaxResults != 0 {
u += fmt.Sprintf("&amp;maxResults=%d", options.MaxResults)
uv.Add("maxResults", strconv.Itoa(options.MaxResults))
}
if options.Expand != "" {
u += fmt.Sprintf("&expand=%s", options.Expand)
uv.Add("expand", options.Expand)
}
if strings.Join(options.Fields, ",") != "" {
u += fmt.Sprintf("&fields=%s", strings.Join(options.Fields, ","))
uv.Add("fields", strings.Join(options.Fields, ","))
}
if options.ValidateQuery != "" {
u += fmt.Sprintf("&validateQuery=%s", options.ValidateQuery)
uv.Add("validateQuery", options.ValidateQuery)
}
}

req, err := s.client.NewRequest("GET", u, nil)
u.RawQuery = uv.Encode()

req, err := s.client.NewRequest("GET", u.String(), nil)
if err != nil {
return []Issue{}, nil, err
}
Expand Down Expand Up @@ -1195,7 +1202,7 @@ func InitIssueWithMetaAndFields(metaProject *MetaProject, metaIssuetype *MetaIss
Value: value,
}
default:
return nil, fmt.Errorf("Unknown issue type encountered: %s for %s", valueType, key)
return nil, fmt.Errorf("unknown issue type encountered: %s for %s", valueType, key)
}
}

Expand Down Expand Up @@ -1240,8 +1247,8 @@ func (s *IssueService) GetWatchers(issueID string) (*[]User, *Response, error) {
}

result := []User{}
user := new(User)
for _, watcher := range watches.Watchers {
var user *User
if watcher.AccountID != "" {
user, resp, err = s.client.User.GetByAccountID(watcher.AccountID)
if err != nil {
Expand Down
Loading

0 comments on commit c65a982

Please sign in to comment.