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

[GH-174] Add Jira Autolink With Comment (#174) #175

Closed
wants to merge 3 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions server/autolink/lib_jira_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,88 @@ var jiraTests = []linkTest{
"Welcome https://mattermost.atlassian.net/browse/MM-12345",
"Welcome [MM-12345](https://mattermost.atlassian.net/browse/MM-12345)",
},
{
"Jump To Comment With Jira Cloud",
autolink.Autolink{
Pattern: "(https://mmtest.atlassian.net/browse/)(DP)(-)(?P<jira_id>\\d+)[?](focusedCommentId)(=)(?P<comment_id>\\d+)",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible for us to have this regex be project-agnostic? This way it can work with on-prem Jira instances with no changes needed. I discussed this in the Jira plugin issue here mattermost/mattermost-plugin-jira#773 (comment). Please me know if this is possible because I'm not sure if it is.

Also, it possible to write a test for the_change that was done for the Jira plugin PR? The goal would be to initialize the autolink plugin with the old Jira autolink config, then update it using setLink, then assert the Looks like we'll need to test this function https://github.com/mattermost/mattermost-plugin-autolink/blob/571d6cd3c642b23c2a6aa1d4fa50cc5965fa1b20/server/api/api.go#L90

@DHaussermann We'll need to test the upgrade path of the Jira plugin that introduces this functionality.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mickmister take a look at #175 (comment) and see if it is ok.

Template: "[DP-${jira_id} With Focused Comment($comment_id)](https://mmtest.atlassian.net/browse/DP-${jira_id}?focusedCommentId=$comment_id)",
},
"https://mmtest.atlassian.net/browse/DP-454?focusedCommentId=11347",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we write a test that doesn't have focusedCommentId in the URL, to test that the regular issue link case works?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#175 (comment) should cover it as well I think.

"[DP-454 With Focused Comment(11347)](https://mmtest.atlassian.net/browse/DP-454?focusedCommentId=11347)",
},
{
"Jump To Comment With Jira Ecc",
autolink.Autolink{
Pattern: "(http://ec2-54-157-116-101.compute-1.amazonaws.com/browse/)(DKHPROJ)(-)(?P<jira_id>\\d+)[?](focusedCommentId)(=)(?P<comment_id>\\d+)",
Template: "[DKHPROJ-${jira_id} With Focused Comment($comment_id)](http://ec2-54-157-116-101.compute-1.amazonaws.com/browse/DKHPROJ-${jira_id}?focusedCommentId=$comment_id)",
},
"http://ec2-54-157-116-101.compute-1.amazonaws.com/browse/DKHPROJ-5?focusedCommentId=10200",
"[DKHPROJ-5 With Focused Comment(10200)](http://ec2-54-157-116-101.compute-1.amazonaws.com/browse/DKHPROJ-5?focusedCommentId=10200)",
},
{
"Jump To Comment With Jira Ecc Long Link",
autolink.Autolink{
Pattern: "(http://ec2-54-157-116-101.compute-1.amazonaws.com/browse/)(DKHPROJ)(-)(?P<jira_id>\\d+)[?](focusedCommentId)(=)(?P<comment_id>\\d+)",
Template: "[DKHPROJ-${jira_id} With Focused Comment($comment_id)](http://ec2-54-157-116-101.compute-1.amazonaws.com/browse/DKHPROJ-${jira_id}?focusedCommentId=$comment_id)",
},
"http://ec2-54-157-116-101.compute-1.amazonaws.com/browse/DKHPROJ-5?focusedCommentId=10200&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-10200",
"http://ec2-54-157-116-101.compute-1.amazonaws.com/browse/DKHPROJ-5?focusedCommentId=10200&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-10200",
},
{
"Jump To Comment With Jira Ecc Long Short",
autolink.Autolink{
Pattern: "(http://ec2-54-157-116-101.compute-1.amazonaws.com/browse/)(DKHPROJ)(-)(?P<jira_id>\\d+)[?](focusedCommentId)(=)(?P<comment_id>\\d+)",
Template: "[DKHPROJ-${jira_id} With Focused Comment($comment_id)](http://ec2-54-157-116-101.compute-1.amazonaws.com/browse/DKHPROJ-${jira_id}?focusedCommentId=$comment_id)",
},
"http://ec2-54-157-116-101.compute-1.amazonaws.com/browse/DKHPROJ-5",
"http://ec2-54-157-116-101.compute-1.amazonaws.com/browse/DKHPROJ-5",
},
{
"Jump To Comment With Jira Cloud Failed",
autolink.Autolink{
Pattern: "(https://mmtest.atlassian.net/browse/)(DP)(-)(?P<jira_id>\\d+)[?](focusedCommentId)(=)(?P<comment_id>\\d+)",
Template: "[DP-${jira_id} With Focused Comment($comment_id)](https://mmtest.atlassian.net/browse/DP-${jira_id}",
},
"https://mmtest.atlassian.net/browse/DP-454",
"https://mmtest.atlassian.net/browse/DP-454",
},
// Trials Linker
{
"Trial With Jira Cloud",
autolink.Autolink{
Pattern: "(?P<URI>.*/)(?P<IssueKey>[A-Za-z]+-[0-9]+)[?](focusedCommentId=*(?P<FocusedCommentId>[^\\s&]+))",
Template: "[${IssueKey} FocusedComment(${FocusedCommentId})](${URI}${IssueKey}?focusedCommentId=${FocusedCommentId})",
},
"https://mmtest.atlassian.net/browse/DP-454?focusedCommentId=11347",
"[DP-454 FocusedComment(11347)](https://mmtest.atlassian.net/browse/DP-454?focusedCommentId=11347)",
},
{
"Trial With Jira Server #1",
autolink.Autolink{
Pattern: "(?P<URI>.*/)(?P<IssueKey>[A-Za-z]+-[0-9]+)[?](focusedCommentId=*(?P<FocusedCommentId>[^\\s&]+))",
Template: "[${IssueKey} FocusedComment(${FocusedCommentId})](${URI}${IssueKey}?focusedCommentId=${FocusedCommentId})",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think just putting (comment) in the link text is enough to show that it's a comment

Suggested change
Template: "[${IssueKey} FocusedComment(${FocusedCommentId})](${URI}${IssueKey}?focusedCommentId=${FocusedCommentId})",
Template: "[${IssueKey} (comment)](${URI}${IssueKey}?focusedCommentId=${FocusedCommentId})",

},
"http://ec2-54-157-116-101.compute-1.amazonaws.com/browse/DKHPROJ-5?focusedCommentId=10200",
"[DKHPROJ-5 FocusedComment(10200)](http://ec2-54-157-116-101.compute-1.amazonaws.com/browse/DKHPROJ-5?focusedCommentId=10200)",
},
{
"Trial With Jira Server #2", //Not Worked here ?
autolink.Autolink{
Pattern: "(?P<URI>.*/)(?P<IssueKey>[A-Za-z]+-[0-9]+)[?](focusedCommentId=*(?P<FocusedCommentId>[^\\s&]+))",
Template: "[${IssueKey} FocusedComment(${FocusedCommentId})](${URI}${IssueKey}?focusedCommentId=${FocusedCommentId})",
},
"http://ec2-54-157-116-101.compute-1.amazonaws.com/browse/DKHPROJ-5?focusedCommentId=10200&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-10200",
"http://ec2-54-157-116-101.compute-1.amazonaws.com/browse/DKHPROJ-5?focusedCommentId=10200&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-10200",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use the regex to "match" the rest of the URL automatically?

},
{
"Trial With Jira Cloud Without Focused Comment ID", //Not Worked here ?
autolink.Autolink{
Pattern: "(?P<URI>.*/)(?P<IssueKey>[A-Za-z]+-[0-9]+)[?](focusedCommentId=*(?P<FocusedCommentId>[^\\s&]+))",
Template: "[${IssueKey} FocusedComment(${FocusedCommentId})](${URI}${IssueKey}?focusedCommentId=${FocusedCommentId})",
},
"https://mmtest.atlassian.net/browse/DP-454",
"https://mmtest.atlassian.net/browse/DP-454",
},
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @mickmister did you mean it will be like this ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we want to continue to be able to transform regular issue URLs like this one above, we'll need to incorporate the existing regexes used in the Jira plugin repo here in these tests. One of the existing regexes defined in the Jira plugin is able to parse this URL in the test above.

Since we have 3 regexes now, we need to have 3x3 = 9 unit tests for the following:

  • The first regex correctly transforms a link its meant to transform
  • The first regex does not change a link that the second regex is meant to transform
  • The first regex does not change a link that the third regex is meant to transform

and so on for the second and third regexes, for a total of 9 tests.

Also, the regexes in the Jira plugin use the Jira instance's URL in the Pattern, so you'll want to do that here as well, instead of using ?P<URI>.*/.

}

func TestJira(t *testing.T) {
Expand Down