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
Handy Uri Template #80
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let’s see what switch the rest looks like
pom.xml
Outdated
@@ -120,6 +120,11 @@ | |||
<scope>test</scope> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.damnhandy</groupId> | |||
<artifactId>handy-uri-templates</artifactId> | |||
<version>2.1.6</version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We’ll need to either pull this into a library plugin or use maskClasses to shield ourselves from class conflicts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the deps: https://github.com/damnhandy/Handy-URI-Templates/blob/master/pom.xml#L473-L533
They are all optional or test scoped except for joda-time.
If we were to put into a library plugin, this is the way to go right: https://github.com/jenkinsci/apache-httpcomponents-client-4-api-plugin with some POM magic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Casz yes, thats the way to go about library plugin. joda-time libraries are used at other places too. It might cause conflicts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stephenc if possible, please advice if I should be doing something special against joda-time or any of the optional dependencies. https://github.com/casz/handy-uri-templates-2-api-plugin/blob/master/pom.xml My maven knowledge is limited
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It they are optional, then they will not be transitive.
I think joda-time may need its own api plugin, in which case you then have to add a jenkins plugin dependency to your api plugin... fun times
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stephenc I give it a shot for the joda-time too :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Joda-time should be safe as well. However I will gladly wrap it in a plugin :)
<dependencies>
<dependency>
<groupId>org.joda</groupId>
<artifactId>joda-convert</artifactId>
<version>1.2</version>
<scope>compile</scope>
<optional>true</optional><!-- mandatory in Scala -->
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently waiting for approval: https://issues.jenkins-ci.org/browse/HOSTING-476
I'll have the next bit up later today |
String url = UriTemplate.fromTemplate(REPO_URL_TEMPLATE + "/hooks/{uuid}") | ||
.set("owner", owner) | ||
.set("repo", repositoryName) | ||
.set("uuid", Util.rawEncode(hook.getUuid())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think i need encoding here as Handy Uri should handle it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, remove the rawEncode as it’s {uuid}
. You’d need to use raw encode if the template was {+uuid}
Map<String,Object> content = JsonParser.mapper.readValue(response, new TypeReference<Map<String,Object>>(){}); | ||
Map page = (Map) content.get("children"); | ||
List<Map> values = (List<Map>) page.get("values"); | ||
collectFileAndDirectories(parent, path, values, files); | ||
while (!(boolean)page.get("isLastPage")){ | ||
response = getRequest(url + String.format("&start=%s&limit=%s", start, 500)); | ||
start += (int) content.get("size"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We were never counting up the pages 😕
Here we are
Lines 725 to 729 in 0f6a106
while(!(boolean)content.get("isLastPage")){ | |
start += (int) content.get("size"); | |
response = getRequest(String.format(url+"&start=%s&limit=&s", start, 500)); | |
content = collectLines(response, lines); | |
} |
However not here
Lines 691 to 695 in 0f6a106
while (!(boolean)page.get("isLastPage")){ | |
response = getRequest(String.format(url+"&start=%s&limit=%s", start, 500)); | |
content = JsonParser.mapper.readValue(response, new TypeReference<Map<String,Object>>(){}); | |
page = (Map) content.get("children"); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you create a JIRA and assign yourself (or let me know the JIRA and i’ll Assign it to you)
Good catch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jira issue created: https://issues.jenkins-ci.org/browse/JENKINS-48279
Can you maybe make a larger limit for the getBranches function while you are at it? Something like 100 maybe instead of the current (25 I think by default). |
I'll try and wrap it in a Jenkins plugin and put it up Jenkins repo tonight, and start the process of having it hosted 👍 |
@stephenc rebased onto master and using snapshot while I wait for hosting 👍 Seems like we are getting rid of all the ugly string format and encoding. Could you please take a look, if I missed anything. If you still think Yoda as a dependency to handy templates, needs to be wrapped. All the dependencies of Yodatime are optional or as test scope. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rsandell can you provide cross-review
pom.xml
Outdated
<dependency> | ||
<groupId>org.jenkins-ci.plugins</groupId> | ||
<artifactId>handy-uri-templates-2-api</artifactId> | ||
<version>2.1.6-1.0-20180102.164938-1</version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merging blocked until this is released
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it just got hosted, so I'll upload it tonight 👍
@@ -460,13 +505,17 @@ private BitbucketRepositoryHooks parsePaginatedRepositoryHooks(String response) | |||
@Override | |||
@CheckForNull | |||
public BitbucketTeam getTeam() throws IOException, InterruptedException { | |||
String url = UriTemplate.fromTemplate("{+base}{/owner}") | |||
.set("base", V2_TEAMS_API_BASE_URL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps we should change this template, I don't like the set "base"
WDYT?
@@ -39,8 +43,32 @@ public void smokes() { | |||
|
|||
@Test | |||
public void getRepositoryUrl() { | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👻 whitespace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rsandell @stephenc WDYT? :)
This is benefitting from handy uri template 🚀 :
Lines 1040 to 1069 in fed749a
String branchUrl; | |
String title; | |
if (head instanceof PullRequestSCMHead) { | |
PullRequestSCMHead pr = (PullRequestSCMHead) head; | |
branchUrl = repoOwner + "/" + repository + "/pull-requests/" + pr.getId(); | |
title = getPullRequestTitleCache().get(pr.getId()); | |
ContributorMetadataAction contributor = getPullRequestContributorCache().get(pr.getId()); | |
if (contributor != null) { | |
result.add(contributor); | |
} | |
} else { | |
branchUrl = repoOwner + "/" + repository + "/branch/" + Util.rawEncode(head.getName()); | |
title = null; | |
} | |
result.add(new BitbucketLink("icon-bitbucket-branch", getServerUrl() + "/" + branchUrl)); | |
result.add(new ObjectMetadataAction(title, null, getServerUrl() + "/" + branchUrl)); | |
} else { | |
String branchUrl; | |
String title; | |
if (head instanceof PullRequestSCMHead) { | |
PullRequestSCMHead pr = (PullRequestSCMHead) head; | |
branchUrl = "projects/" + repoOwner + "/repos/" + repository + "/pull-requests/" +pr.getId()+"/overview"; | |
title = getPullRequestTitleCache().get(pr.getId()); | |
ContributorMetadataAction contributor = getPullRequestContributorCache().get(pr.getId()); | |
if (contributor != null) { | |
result.add(contributor); | |
} | |
} else { | |
branchUrl = "projects/" + repoOwner + "/repos/" + repository + "/compare/commits" | |
+ "?sourceBranch=" + URLEncoder.encode(Constants.R_HEADS + head.getName(), "UTF-8"); |
@@ -726,13 +827,24 @@ public InputStream getFileContent(BitbucketSCMFile file) throws IOException, Int | |||
String path = encodePath(file.getPath()); | |||
String ref = URLEncoder.encode(file.getRef(), "UTF-8"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no longer needed?
@@ -726,13 +827,24 @@ public InputStream getFileContent(BitbucketSCMFile file) throws IOException, Int | |||
String path = encodePath(file.getPath()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no longer needed?
@@ -689,15 +779,26 @@ private String deleteRequest(String path) throws IOException { | |||
String path = encodePath(directory.getPath()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no longer needed?
@@ -689,15 +779,26 @@ private String deleteRequest(String path) throws IOException { | |||
String path = encodePath(directory.getPath()); | |||
String ref = URLEncoder.encode(directory.getRef(), "UTF-8"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no longer needed?
Tested with both bitbucket cloud and bitbucket server that URL's and scans still work 👍 🚀
|
Can we get uri templates on Lines 1040 to 1069 in fed749a
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks much cleaner
} | ||
if (head instanceof PullRequestSCMHead) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The if-else above is now only for URL template and this is now deduped.
} | ||
String url = template.expand(); | ||
result.add(new BitbucketLink("icon-bitbucket-branch", url)); | ||
result.add(new ObjectMetadataAction(title, null, url)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More deduping
template.set("owner", repoOwner).set("repo", repository); | ||
String url = template.expand(); | ||
result.add(new BitbucketLink("icon-bitbucket-repo", url)); | ||
result.add(new ObjectMetadataAction(r.getRepositoryName(), null, url)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some more needed deduping
Looks like its ready to be merged. @stephenc, looks good to you? |
Let’s go |
[FIXED JENKINS-41883] Append global log on open
Just initial work, to get some feedback
cc @stephenc