Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comments are not being added to issues #604

Open
justaugustus opened this issue Jan 4, 2023 · 5 comments
Open

Comments are not being added to issues #604

justaugustus opened this issue Jan 4, 2023 · 5 comments

Comments

@justaugustus
Copy link

justaugustus commented Jan 4, 2023

What happened?

I maintain a tool, gh-jira-issue-sync, which can (one-way) sync issues from GitHub to Jira.

Well, sort of.
I'm currently running into problems copying comments from a GitHub issue to its Jira issue.

Here's a snippet of what that failure looks like:

DEBU[0002] Updating JIRA SYNC-57 with GitHub #50         app=gh-jira-issue-sync
DEBU[0002] Comparing GitHub issue #50 and JIRA issue SYNC-57  app=gh-jira-issue-sync
DEBU[0002] Issues have any differences: false            app=gh-jira-issue-sync
DEBU[0002] JIRA issue SYNC-57 is already up to date!     app=gh-jira-issue-sync
DEBU[0002] JIRA issue SYNC-57 has 0 comments             app=gh-jira-issue-sync
DEBU[0002] Retrieving GitHub user (justaugustus)         app=gh-jira-issue-sync
ERRO[0002] Error performing operation; retrying in 552ms: Invalid request payload. Refer to the REST API documentation and try again.: request failed. Please analyze the request body for more details. Status code: 400  app=gh-jira-issue-sync
ERRO[0003] Error performing operation; retrying in 1.08s: Invalid request payload. Refer to the REST API documentation and try again.: request failed. Please analyze the request body for more details. Status code: 400  app=gh-jira-issue-sync
ERRO[0004] Error performing operation; retrying in 1.31s: Invalid request payload. Refer to the REST API documentation and try again.: request failed. Please analyze the request body for more details. Status code: 400  app=gh-jira-issue-sync
ERRO[0005] Error performing operation; retrying in 1.582s: Invalid request payload. Refer to the REST API documentation and try again.: request failed. Please analyze the request body for more details. Status code: 400  app=gh-jira-issue-sync
ERRO[0007] Error performing operation; retrying in 2.34s: Invalid request payload. Refer to the REST API documentation and try again.: request failed. Please analyze the request body for more details. Status code: 400  app=gh-jira-issue-sync
ERRO[0009] Error performing operation; retrying in 4.506s: Invalid request payload. Refer to the REST API documentation and try again.: request failed. Please analyze the request body for more details. Status code: 400  app=gh-jira-issue-sync
ERRO[0014] Error performing operation; retrying in 3.221s: Invalid request payload. Refer to the REST API documentation and try again.: request failed. Please analyze the request body for more details. Status code: 400  app=gh-jira-issue-sync
ERRO[0017] Error performing operation; retrying in 5.608s: Invalid request payload. Refer to the REST API documentation and try again.: request failed. Please analyze the request body for more details. Status code: 400  app=gh-jira-issue-sync
ERRO[0023] Error performing operation; retrying in 7.649s: Invalid request payload. Refer to the REST API documentation and try again.: request failed. Please analyze the request body for more details. Status code: 400  app=gh-jira-issue-sync
ERRO[0031] Error creating JIRA comment on issue SYNC-57. Error: request error: backoff error: retry notify: Invalid request payload. Refer to the REST API documentation and try again.: request failed. Please analyze the request body for more details. Status code: 400  app=gh-jira-issue-sync
ERRO[0031] Error occurred trying to read error body: http2: response body closed  app=gh-jira-issue-sync
ERRO[0031] Error updating issue SYNC-57. Error: comparing comments for issue SYNC-57: creating Jira comment: reading error body: http2: response body closed  app=gh-jira-issue-sync

This tool was forked from https://github.com/coreos/issue-sync, which also used andygrunwald/go-jira (v1), but was last updated in 2019 (ref: coreos/issue-sync@ea9d009).

A few things could be happening:

  • The original downstream code (which lacks testing) contains inaccurate logic for comment creation
  • There are significant differences between go-jira/v1 and go-jira/v2 comment logic which the downstream has not been updated to reflect after bumping to 0946977 in go.mod: Update to github.com/andygrunwald/go-jira/v2 uwu-tools/gh-jira-issue-sync#40
  • Downstream request backoff logic has bugs/is mangling the go-jira request
  • Comments with spacing or formatting issues e.g., markdown vs Jira formatting are not properly handled in the go-jira request body
  • Human (me) error (highly possible)

What did you expect to happen?

Comments are added to issues.

How can we reproduce it (as minimally and precisely as possible)?

The simplest way is probably to run https://github.com/uwu-tools/gh-jira-issue-sync.

Here are some relevant code snippets:

Anything else we need to know?

Thanks for this maintaining this module, @andygrunwald!

It's entirely possible that this is strictly a downstream bug, but I wanted to file this just in case, since I can see you're working on the move to Jira v2/v3 in #489 / https://github.com/andygrunwald/go-jira/milestone/1 / #501.

Here's the downstream tracking issue: uwu-tools/gh-jira-issue-sync#62

Your Environment

Include as many relevant details about the environment you experienced the problem in

@justaugustus
Copy link
Author

Hey @andygrunwald, just wanted to check in and see if you had a chance to take a peek at this one?

@andygrunwald
Copy link
Owner

@justaugustus Sorry, time is a bit limited at the moment. Great issue description btw.

Would it be possible to have a minimalistic code example without the code structure
of https://github.com/uwu-tools/gh-jira-issue-sync ?

@rwojsznis
Copy link

rwojsznis commented Mar 19, 2023

Hey @justaugustus, just FYI - I ran into same issue 😜

Some investigation showed that AddComment methods serializes Author and UpdateAuthor or User type:

// Comment represents a comment by a person to an issue in Jira.
type Comment struct {
	ID           string            `json:"id,omitempty" structs:"id,omitempty"`
	Self         string            `json:"self,omitempty" structs:"self,omitempty"`
	Name         string            `json:"name,omitempty" structs:"name,omitempty"`
	Author       User              `json:"author,omitempty" structs:"author,omitempty"`
	Body         string            `json:"body,omitempty" structs:"body,omitempty"`
	UpdateAuthor User              `json:"updateAuthor,omitempty" structs:"updateAuthor,omitempty"`
	Updated      string            `json:"updated,omitempty" structs:"updated,omitempty"`
	Created      string            `json:"created,omitempty" structs:"created,omitempty"`
	Visibility   CommentVisibility `json:"visibility,omitempty" structs:"visibility,omitempty"`

	// A list of comment properties. Optional on create and update.
	Properties []EntityProperty `json:"properties,omitempty" structs:"properties,omitempty"`
}

I'm definitely no go expert, but it seems like omitempty will have no effect (as we're not using pointers) and our User structs will get serialized to empty structs within this HTTP call and that seems to be causing 400 error coming from JIRA.

Getting rid of {"author":{"avatarUrls":{},"groups":{},"applicationRoles":{}} and "updateAuthor":{"avatarUrls":{},"groups":{},"applicationRoles":{}},"visibility":{}} parts from the json request it seems to be fixing the problem.

As a workaround you can define custom struct and just make a HTTP using your jira.Client, some semi-working code would be as follows:

// I was only interesting in adding a simple comment
type JiraSimpleComment struct {
	Body string `json:"body"`
}

apiEndpoint := fmt.Sprintf("rest/api/2/issue/%s/comment", issue.ID)
req, err := client.NewRequest(context.Background(), http.MethodPost, apiEndpoint, comment)

if err != nil {
	return err
}
responseComment := new(jira.Comment)
_, err = jr.client.Do(req, responseComment)
if err != nil {
	return err
}
// ...

Let me know if that helps, cheers!

edit: oh, I'm using BasicAuthTransport with APIToken, not sure if that matters in that particular case tbh, didn't really dig that deep here 😅

@andygrunwald
Copy link
Owner

Thanks!
I will just keep this open for fixing later. Happy to accept PRs for docs or anything else.

@justaugustus
Copy link
Author

@andygrunwald — based on @lgecse's testing, it looks like the PR @LaurenceTews fixes this.

Could you review #640 when you have a chance?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants