|
35 | 35 | import java.util.Map; |
36 | 36 | import java.util.Objects; |
37 | 37 | import java.util.Set; |
| 38 | +import java.util.concurrent.ConcurrentHashMap; |
38 | 39 | import java.util.stream.Collectors; |
39 | 40 | import jenkins.model.Jenkins; |
40 | 41 | import jenkins.plugins.git.AbstractGitSCMSource; |
|
54 | 55 | import jenkins.scm.api.SCMSourceDescriptor; |
55 | 56 | import jenkins.scm.api.SCMSourceEvent; |
56 | 57 | import jenkins.scm.api.SCMSourceOwner; |
| 58 | +import jenkins.scm.api.metadata.ContributorMetadataAction; |
57 | 59 | import jenkins.scm.api.metadata.ObjectMetadataAction; |
58 | 60 | import jenkins.scm.api.metadata.PrimaryInstanceMetadataAction; |
59 | 61 | import jenkins.scm.api.mixin.ChangeRequestCheckoutStrategy; |
@@ -111,6 +113,17 @@ public class GitLabSCMSource extends AbstractGitSCMSource { |
111 | 113 | private transient Project gitlabProject; |
112 | 114 | private int projectId = -1; |
113 | 115 |
|
| 116 | + /** |
| 117 | + * The cache of {@link ObjectMetadataAction} instances for each open MR. |
| 118 | + */ |
| 119 | + @NonNull |
| 120 | + private transient /*effectively final*/ Map<Integer,ObjectMetadataAction> mergeRequestMetadataCache = new ConcurrentHashMap<>(); |
| 121 | + /** |
| 122 | + * The cache of {@link ObjectMetadataAction} instances for each open MR. |
| 123 | + */ |
| 124 | + @NonNull |
| 125 | + private transient /*effectively final*/ Map<Integer,ContributorMetadataAction> mergeRequestContributorCache = new ConcurrentHashMap<>(); |
| 126 | + |
114 | 127 | @DataBoundConstructor |
115 | 128 | public GitLabSCMSource(String serverName, String projectOwner, String projectPath) { |
116 | 129 | this.serverName = serverName; |
@@ -354,6 +367,18 @@ public SCMSourceCriteria.Probe create(@NonNull BranchSCMHead head, |
354 | 367 | final MergeRequest m = |
355 | 368 | gitLabApi.getMergeRequestApi() |
356 | 369 | .getMergeRequest(gitlabProject, mr.getIid()); |
| 370 | + mergeRequestContributorCache.put(mr.getIid(), |
| 371 | + new ContributorMetadataAction( |
| 372 | + mr.getAuthor().getUsername(), |
| 373 | + mr.getAuthor().getName(), |
| 374 | + mr.getAuthor().getEmail() |
| 375 | + )); |
| 376 | + mergeRequestMetadataCache.put(mr.getIid(), |
| 377 | + new ObjectMetadataAction( |
| 378 | + mr.getTitle(), |
| 379 | + mr.getDescription(), |
| 380 | + mr.getWebUrl() |
| 381 | + )); |
357 | 382 | count++; |
358 | 383 | listener.getLogger().format("%nChecking merge request %s%n", |
359 | 384 | HyperlinkNote.encodeTo( |
@@ -560,15 +585,21 @@ protected List<Action> retrieveActions(@NonNull SCMHead head, SCMHeadEvent event |
560 | 585 | result.add(new PrimaryInstanceMetadataAction()); |
561 | 586 | } |
562 | 587 | } else if (head instanceof MergeRequestSCMHead) { |
| 588 | + int iid = Integer.parseInt(((MergeRequestSCMHead) head).getId()); |
563 | 589 | String mergeUrl = mergeRequestUriTemplate(serverName) |
564 | 590 | .set("project", splitPath(projectPath)) |
565 | | - .set("iid", ((MergeRequestSCMHead) head).getId()) |
| 591 | + .set("iid", iid) |
566 | 592 | .expand(); |
567 | | - result.add(new ObjectMetadataAction( |
568 | | - null, |
569 | | - null, |
570 | | - mergeUrl |
571 | | - )); |
| 593 | + ObjectMetadataAction metadataAction = mergeRequestMetadataCache.get(iid); |
| 594 | + if (metadataAction == null) { |
| 595 | + // best effort |
| 596 | + metadataAction = new ObjectMetadataAction(null, null, mergeUrl); |
| 597 | + } |
| 598 | + result.add(metadataAction); |
| 599 | + ContributorMetadataAction contributor = mergeRequestContributorCache.get(iid); |
| 600 | + if (contributor != null) { |
| 601 | + result.add(contributor); |
| 602 | + } |
572 | 603 | result.add(GitLabLink.toMergeRequest(mergeUrl)); |
573 | 604 | } else if (head instanceof GitLabTagSCMHead) { |
574 | 605 | String tagUrl = tagUriTemplate(serverName) |
@@ -806,9 +837,6 @@ public ListBoxModel doFillProjectPathItems(@AncestorInPath SCMSourceOwner contex |
806 | 837 | } |
807 | 838 |
|
808 | 839 | if (projectOwner.equals("")) { |
809 | | -// for(Project p : gitLabApi.getProjectApi().getOwnedProjects()) { |
810 | | -// result.add(p.getPathWithNamespace()); |
811 | | -// } |
812 | 840 | return new StandardListBoxModel().includeEmptyValue(); |
813 | 841 | } |
814 | 842 | try { |
|
0 commit comments