> {
85 |
86 | @NonNull
87 | public String getDisplayName() {
88 | return "GitLab";
89 | }
90 |
91 | @Override
92 | public GitLabBrowser newInstance(StaplerRequest2 req, @NonNull JSONObject jsonObject) throws FormException {
93 | return req.bindJSON(GitLabBrowser.class, jsonObject);
94 | }
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabGroup.java:
--------------------------------------------------------------------------------
1 | package io.jenkins.plugins.gitlabbranchsource.helpers;
2 |
3 | public class GitLabGroup extends GitLabOwner {
4 |
5 | private String fullName;
6 | private String description;
7 |
8 | public GitLabGroup(String name, String webUrl, String avatarUrl, Long id, String fullName, String description) {
9 | super(name, webUrl, avatarUrl, id);
10 | this.fullName = fullName;
11 | this.description = description;
12 | }
13 |
14 | @Override
15 | public String getFullName() {
16 | return fullName;
17 | }
18 |
19 | public void setFullName(String fullName) {
20 | this.fullName = fullName;
21 | }
22 |
23 | @Override
24 | public String getWord() {
25 | if (fullName.indexOf('/') == -1) {
26 | return "Group";
27 | }
28 | return "Subgroup";
29 | }
30 |
31 | public String getDescription() {
32 | return description;
33 | }
34 |
35 | public void setDescription(String description) {
36 | this.description = description;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabIcons.java:
--------------------------------------------------------------------------------
1 | package io.jenkins.plugins.gitlabbranchsource.helpers;
2 |
3 | import static org.jenkins.ui.icon.Icon.ICON_LARGE_STYLE;
4 | import static org.jenkins.ui.icon.Icon.ICON_MEDIUM_STYLE;
5 | import static org.jenkins.ui.icon.Icon.ICON_SMALL_STYLE;
6 | import static org.jenkins.ui.icon.Icon.ICON_XLARGE_STYLE;
7 | import static org.jenkins.ui.icon.IconSet.icons;
8 |
9 | import hudson.init.Initializer;
10 | import java.util.NoSuchElementException;
11 | import jenkins.model.Jenkins;
12 | import org.apache.commons.jelly.JellyContext;
13 | import org.jenkins.ui.icon.Icon;
14 | import org.kohsuke.stapler.Stapler;
15 |
16 | public final class GitLabIcons {
17 |
18 | public static final String ICON_PROJECT = "gitlab-project";
19 | public static final String ICON_BRANCH = "gitlab-branch";
20 | public static final String ICON_GITLAB = "gitlab-logo";
21 | public static final String ICON_COMMIT = "gitlab-commit";
22 | public static final String ICON_MR = "gitlab-mr";
23 | public static final String ICON_TAG = "gitlab-tag";
24 | private static final String ICON_PATH = "plugin/gitlab-branch-source/images/";
25 |
26 | private GitLabIcons() {
27 | /* no instances allowed */
28 | }
29 |
30 | @Initializer
31 | public static void initialize() {
32 | addIcon(ICON_GITLAB);
33 | addIcon(ICON_PROJECT);
34 | addIcon(ICON_BRANCH);
35 | addIcon(ICON_COMMIT);
36 | addIcon(ICON_MR);
37 | addIcon(ICON_TAG);
38 | }
39 |
40 | public static String iconFileName(String name, Size size) {
41 | Icon icon = icons.getIconByClassSpec(classSpec(name, size));
42 | if (icon == null) {
43 | return null;
44 | }
45 |
46 | JellyContext ctx = new JellyContext();
47 | ctx.setVariable("resURL", Stapler.getCurrentRequest2().getContextPath() + Jenkins.RESOURCE_PATH);
48 | return icon.getQualifiedUrl(ctx);
49 | }
50 |
51 | public static String iconFilePathPattern(String name) {
52 | return ICON_PATH + name + ".svg";
53 | }
54 |
55 | private static String classSpec(String name, Size size) {
56 | return name + " " + size.className;
57 | }
58 |
59 | private static void addIcon(String name) {
60 | for (Size size : Size.values()) {
61 | icons.addIcon(new Icon(classSpec(name, size), ICON_PATH + "/" + name + ".svg", size.style));
62 | }
63 | }
64 |
65 | public enum Size {
66 | SMALL("icon-sm", "16x16", ICON_SMALL_STYLE),
67 | MEDIUM("icon-md", "24x24", ICON_MEDIUM_STYLE),
68 | LARGE("icon-lg", "32x32", ICON_LARGE_STYLE),
69 | XLARGE("icon-xlg", "48x48", ICON_XLARGE_STYLE);
70 |
71 | private final String className;
72 | private final String dimensions;
73 | private final String style;
74 |
75 | Size(String className, String dimensions, String style) {
76 | this.className = className;
77 | this.dimensions = dimensions;
78 | this.style = style;
79 | }
80 |
81 | public static Size byDimensions(String dimensions) {
82 | for (Size s : values()) {
83 | if (s.dimensions.equals(dimensions)) {
84 | return s;
85 | }
86 | }
87 | throw new NoSuchElementException("unknown dimensions: " + dimensions);
88 | }
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabLink.java:
--------------------------------------------------------------------------------
1 | package io.jenkins.plugins.gitlabbranchsource.helpers;
2 |
3 | import static org.apache.commons.lang.StringUtils.defaultIfBlank;
4 |
5 | import edu.umd.cs.findbugs.annotations.NonNull;
6 | import hudson.model.Action;
7 | import jenkins.model.Jenkins;
8 | import org.apache.commons.jelly.JellyContext;
9 | import org.jenkins.ui.icon.Icon;
10 | import org.jenkins.ui.icon.IconSet;
11 | import org.jenkins.ui.icon.IconSpec;
12 | import org.kohsuke.stapler.Stapler;
13 |
14 | /**
15 | * Link to GitLab
16 | */
17 | public class GitLabLink implements Action, IconSpec {
18 |
19 | /**
20 | * The icon class name to use.
21 | */
22 | @NonNull
23 | private final String iconClassName;
24 |
25 | /**
26 | * Target of the hyperlink to take the user to.
27 | */
28 | @NonNull
29 | private final String url;
30 |
31 | private String displayName;
32 |
33 | public GitLabLink(@NonNull String iconClassName, @NonNull String url) {
34 | this.iconClassName = iconClassName;
35 | this.url = url;
36 | this.displayName = "";
37 | }
38 |
39 | public GitLabLink(@NonNull String iconClassName, @NonNull String url, String displayName) {
40 | this.iconClassName = iconClassName;
41 | this.url = url;
42 | this.displayName = displayName;
43 | }
44 |
45 | public static GitLabLink toGroup(String url) {
46 | return new GitLabLink("gitlab-logo", url, "Group");
47 | }
48 |
49 | public static GitLabLink toProject(String url) {
50 | return new GitLabLink("gitlab-project", url, "Project");
51 | }
52 |
53 | public static GitLabLink toBranch(String url) {
54 | return new GitLabLink("gitlab-branch", url, "Branch");
55 | }
56 |
57 | public static GitLabLink toMergeRequest(String url) {
58 | return new GitLabLink("gitlab-mr", url, "Merge Request");
59 | }
60 |
61 | public static GitLabLink toTag(String url) {
62 | return new GitLabLink("gitlab-tag", url, "Tag");
63 | }
64 |
65 | public static GitLabLink toCommit(String url) {
66 | return new GitLabLink("gitlab-commit", url, "Commit");
67 | }
68 |
69 | @NonNull
70 | public String getUrl() {
71 | return url;
72 | }
73 |
74 | @NonNull
75 | @Override
76 | public String getIconClassName() {
77 | return iconClassName;
78 | }
79 |
80 | @Override
81 | public String getIconFileName() {
82 | String iconClassName = getIconClassName();
83 | Icon icon = IconSet.icons.getIconByClassSpec(iconClassName + " icon-md");
84 | if (icon != null) {
85 | JellyContext ctx = new JellyContext();
86 | ctx.setVariable("resURL", Stapler.getCurrentRequest2().getContextPath() + Jenkins.RESOURCE_PATH);
87 | return icon.getQualifiedUrl(ctx);
88 | }
89 | return null;
90 | }
91 |
92 | @Override
93 | public String getDisplayName() {
94 | return defaultIfBlank(displayName, "GitLab");
95 | }
96 |
97 | public void setDisplayName(@NonNull String displayName) {
98 | this.displayName = displayName;
99 | }
100 |
101 | @Override
102 | public String getUrlName() {
103 | return url;
104 | }
105 |
106 | @Override
107 | public int hashCode() {
108 | int result = iconClassName.hashCode();
109 | result = 31 * result + url.hashCode();
110 | return result;
111 | }
112 |
113 | @Override
114 | public boolean equals(Object o) {
115 | if (this == o) {
116 | return true;
117 | }
118 | if (o == null || getClass() != o.getClass()) {
119 | return false;
120 | }
121 |
122 | GitLabLink that = (GitLabLink) o;
123 |
124 | if (!iconClassName.equals(that.iconClassName)) {
125 | return false;
126 | }
127 | return url.equals(that.url);
128 | }
129 |
130 | @Override
131 | public String toString() {
132 | return "GitLabLink{" + "iconClassName='" + iconClassName + '\'' + ", url='" + url + '\'' + '}';
133 | }
134 | }
135 |
--------------------------------------------------------------------------------
/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabOwner.java:
--------------------------------------------------------------------------------
1 | package io.jenkins.plugins.gitlabbranchsource.helpers;
2 |
3 | import edu.umd.cs.findbugs.annotations.NonNull;
4 | import org.gitlab4j.api.GitLabApi;
5 | import org.gitlab4j.api.GitLabApiException;
6 | import org.gitlab4j.api.models.Group;
7 | import org.gitlab4j.api.models.User;
8 |
9 | public abstract class GitLabOwner {
10 |
11 | private String name;
12 | private String webUrl;
13 | private String avatarUrl;
14 | private Long id;
15 |
16 | public GitLabOwner(String name, String webUrl, String avatarUrl, Long id) {
17 | this.name = name;
18 | this.webUrl = webUrl;
19 | this.avatarUrl = avatarUrl;
20 | this.id = id;
21 | }
22 |
23 | @NonNull
24 | public static GitLabOwner fetchOwner(GitLabApi gitLabApi, String projectOwner) {
25 | try {
26 | Group group = gitLabApi.getGroupApi().getGroup(projectOwner);
27 | return new GitLabGroup(
28 | group.getName(),
29 | group.getWebUrl(),
30 | group.getAvatarUrl(),
31 | group.getId(),
32 | group.getFullName(),
33 | group.getDescription());
34 | } catch (GitLabApiException e) {
35 | if (e.getHttpStatus() != 404) {
36 | throw new IllegalStateException("Unable to fetch Group", e);
37 | }
38 |
39 | try {
40 | User user = gitLabApi.getUserApi().getUser(projectOwner);
41 | // If user is not found, null is returned
42 | if (user == null) {
43 | throw new IllegalStateException(
44 | String.format("Owner '%s' is neither a user/group/subgroup", projectOwner));
45 | }
46 | return new GitLabUser(user.getName(), user.getWebUrl(), user.getAvatarUrl(), user.getId());
47 | } catch (GitLabApiException e1) {
48 | throw new IllegalStateException("Unable to fetch User", e1);
49 | }
50 | }
51 | }
52 |
53 | public String getName() {
54 | return name;
55 | }
56 |
57 | public void setName(String name) {
58 | this.name = name;
59 | }
60 |
61 | public String getFullName() {
62 | return name;
63 | }
64 |
65 | public String getWebUrl() {
66 | return webUrl;
67 | }
68 |
69 | public void setWebUrl(String webUrl) {
70 | this.webUrl = webUrl;
71 | }
72 |
73 | public String getAvatarUrl() {
74 | return avatarUrl;
75 | }
76 |
77 | public void setAvatarUrl(String avatarUrl) {
78 | this.avatarUrl = avatarUrl;
79 | }
80 |
81 | public Long getId() {
82 | return id;
83 | }
84 |
85 | public void setId(Long id) {
86 | this.id = id;
87 | }
88 |
89 | public abstract String getWord();
90 | }
91 |
--------------------------------------------------------------------------------
/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabUser.java:
--------------------------------------------------------------------------------
1 | package io.jenkins.plugins.gitlabbranchsource.helpers;
2 |
3 | public class GitLabUser extends GitLabOwner {
4 |
5 | public GitLabUser(String name, String webUrl, String avatarUrl, Long id) {
6 | super(name, webUrl, avatarUrl, id);
7 | }
8 |
9 | @Override
10 | public String getWord() {
11 | return "User";
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/io/jenkins/plugins/gitlabbranchsource/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Jenkins SCM API implementation for GitLab .
3 | *
4 | * The primary entry points for the implementation are:
5 | *
6 | *
7 | * {@link io.jenkins.plugins.gitlabbranchsource.GitLabSCMSource} - the {@link jenkins.scm.api.SCMSource} implementation
8 | * {@link io.jenkins.plugins.gitlabbranchsource.GitLabSCMNavigator} - the {@link jenkins.scm.api.SCMNavigator}
9 | * implementation
10 | *
11 | *
12 | * These implementations are {@link jenkins.scm.api.trait.SCMTrait} based and accept the traits for
13 | * {@link jenkins.plugins.git.AbstractGitSCMSource} as well as the GitLab specific traits:
14 | *
15 | * {@link io.jenkins.plugins.gitlabbranchsource.BranchDiscoveryTrait}
16 | * {@link io.jenkins.plugins.gitlabbranchsource.ForkMergeRequestDiscoveryTrait}
17 | * {@link io.jenkins.plugins.gitlabbranchsource.OriginMergeRequestDiscoveryTrait}
18 | * {@link io.jenkins.plugins.gitlabbranchsource.SSHCheckoutTrait}
19 | * {@link io.jenkins.plugins.gitlabbranchsource.HookRegistrationTrait}
20 | *
21 | *
22 | * Extension plugins wanting to add GitLab-specific traits should target at least one of:
23 | *
24 | * {@link io.jenkins.plugins.gitlabbranchsource.GitLabSCMNavigatorContext} for
25 | * {@linkplain jenkins.scm.api.trait.SCMNavigatorTrait}s
26 | * {@link io.jenkins.plugins.gitlabbranchsource.GitLabSCMNavigatorRequest} for
27 | * {@linkplain jenkins.scm.api.trait.SCMNavigatorTrait}s
28 | * {@link io.jenkins.plugins.gitlabbranchsource.GitLabSCMSourceBuilder} for
29 | * {@linkplain jenkins.scm.api.trait.SCMNavigatorTrait}s
30 | * {@link io.jenkins.plugins.gitlabbranchsource.GitLabSCMSourceContext} for
31 | * {@linkplain jenkins.scm.api.trait.SCMSourceTrait}s
32 | * {@link io.jenkins.plugins.gitlabbranchsource.GitLabSCMSourceRequest} for
33 | * {@linkplain jenkins.scm.api.trait.SCMSourceTrait}s
34 | * {@link io.jenkins.plugins.gitlabbranchsource.GitLabSCMBuilder} for
35 | * {@linkplain jenkins.scm.api.trait.SCMSourceTrait}s
36 | *
37 | */
38 | package io.jenkins.plugins.gitlabbranchsource;
39 |
--------------------------------------------------------------------------------
/src/main/java/io/jenkins/plugins/gitlabserverconfig/action/GitlabAction.java:
--------------------------------------------------------------------------------
1 | package io.jenkins.plugins.gitlabserverconfig.action;
2 |
3 | import edu.umd.cs.findbugs.annotations.CheckForNull;
4 | import hudson.Extension;
5 | import hudson.model.RootAction;
6 | import hudson.util.HttpResponses;
7 | import io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper;
8 | import io.jenkins.plugins.gitlabserverconfig.servers.GitLabServers;
9 | import java.util.logging.Level;
10 | import java.util.logging.Logger;
11 | import jenkins.model.Jenkins;
12 | import jenkins.scm.api.SCMSourceOwner;
13 | import net.sf.json.JSONArray;
14 | import net.sf.json.JSONObject;
15 | import org.apache.commons.lang.StringUtils;
16 | import org.gitlab4j.api.GitLabApi;
17 | import org.gitlab4j.api.GitLabApiException;
18 | import org.gitlab4j.api.models.Project;
19 | import org.gitlab4j.api.models.ProjectFilter;
20 | import org.kohsuke.accmod.Restricted;
21 | import org.kohsuke.accmod.restrictions.NoExternalUse;
22 | import org.kohsuke.stapler.AncestorInPath;
23 | import org.kohsuke.stapler.HttpResponse;
24 | import org.kohsuke.stapler.QueryParameter;
25 | import org.kohsuke.stapler.interceptor.RequirePOST;
26 |
27 | /**
28 | * Provide an API for Jenkins integration purpose
29 | */
30 | @Extension
31 | @Restricted(NoExternalUse.class)
32 | public class GitlabAction implements RootAction {
33 | public static final Logger LOGGER = Logger.getLogger(GitlabAction.class.getName());
34 |
35 | @RequirePOST
36 | public HttpResponse doServerList() {
37 | if (!Jenkins.get().hasPermission(Jenkins.MANAGE)) {
38 | return HttpResponses.errorJSON("no permission to get Gitlab server list");
39 | }
40 |
41 | JSONArray servers = new JSONArray();
42 | GitLabServers.get().getServers().forEach(server -> {
43 | JSONObject serverObj = new JSONObject();
44 | serverObj.put("name", server.getName());
45 | serverObj.put("url", server.getServerUrl());
46 | servers.add(serverObj);
47 | });
48 |
49 | return HttpResponses.okJSON(servers);
50 | }
51 |
52 | @RequirePOST
53 | public HttpResponse doProjectList(
54 | @AncestorInPath SCMSourceOwner context, @QueryParameter String server, @QueryParameter String owner) {
55 | if (!Jenkins.get().hasPermission(Jenkins.MANAGE)) {
56 | return HttpResponses.errorJSON("no permission to get Gitlab server list");
57 | }
58 |
59 | if (StringUtils.isEmpty(server) || StringUtils.isEmpty(owner)) {
60 | return HttpResponses.errorJSON("server or owner is empty");
61 | }
62 |
63 | JSONArray servers = new JSONArray();
64 |
65 | GitLabApi gitLabApi = GitLabHelper.apiBuilder(context, server);
66 | try {
67 | for (Project project :
68 | gitLabApi.getProjectApi().getUserProjects(owner, new ProjectFilter().withOwned(true))) {
69 | servers.add(project.getPathWithNamespace());
70 | }
71 | } catch (GitLabApiException e) {
72 | LOGGER.log(Level.FINE, String.format("errors when get projects from %s/%s as a user", server, owner), e);
73 | }
74 |
75 | try {
76 | for (Project project : gitLabApi.getGroupApi().getProjects(owner)) {
77 | servers.add(project.getPathWithNamespace());
78 | }
79 | } catch (GitLabApiException e) {
80 | LOGGER.log(Level.FINE, String.format("errors when get projects from %s/%s as a group", server, owner), e);
81 | }
82 |
83 | return HttpResponses.okJSON(servers);
84 | }
85 |
86 | @CheckForNull
87 | @Override
88 | public String getIconFileName() {
89 | return null;
90 | }
91 |
92 | @CheckForNull
93 | @Override
94 | public String getDisplayName() {
95 | return null;
96 | }
97 |
98 | @CheckForNull
99 | @Override
100 | public String getUrlName() {
101 | return "/gitlab";
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/src/main/java/io/jenkins/plugins/gitlabserverconfig/credentials/PersonalAccessToken.java:
--------------------------------------------------------------------------------
1 | package io.jenkins.plugins.gitlabserverconfig.credentials;
2 |
3 | import com.cloudbees.plugins.credentials.common.StandardCredentials;
4 | import edu.umd.cs.findbugs.annotations.NonNull;
5 | import hudson.util.Secret;
6 |
7 | public interface PersonalAccessToken extends StandardCredentials {
8 |
9 | /**
10 | * Returns the token.
11 | *
12 | * @return the token.
13 | */
14 | @NonNull
15 | Secret getToken();
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/io/jenkins/plugins/gitlabserverconfig/credentials/PersonalAccessTokenImpl.java:
--------------------------------------------------------------------------------
1 | package io.jenkins.plugins.gitlabserverconfig.credentials;
2 |
3 | import com.cloudbees.plugins.credentials.CredentialsDescriptor;
4 | import com.cloudbees.plugins.credentials.CredentialsProvider;
5 | import com.cloudbees.plugins.credentials.CredentialsScope;
6 | import com.cloudbees.plugins.credentials.impl.BaseStandardCredentials;
7 | import edu.umd.cs.findbugs.annotations.CheckForNull;
8 | import edu.umd.cs.findbugs.annotations.NonNull;
9 | import hudson.Extension;
10 | import hudson.util.FormValidation;
11 | import hudson.util.Secret;
12 | import jenkins.model.Jenkins;
13 | import org.apache.commons.lang.StringUtils;
14 | import org.jenkinsci.Symbol;
15 | import org.kohsuke.accmod.Restricted;
16 | import org.kohsuke.accmod.restrictions.NoExternalUse;
17 | import org.kohsuke.stapler.DataBoundConstructor;
18 | import org.kohsuke.stapler.QueryParameter;
19 |
20 | /**
21 | * Default implementation of {@link PersonalAccessToken} for use by {@link Jenkins} {@link
22 | * CredentialsProvider} instances that store {@link Secret} locally.
23 | */
24 | public class PersonalAccessTokenImpl extends BaseStandardCredentials implements PersonalAccessToken {
25 |
26 | /**
27 | * Our token.
28 | */
29 | @NonNull
30 | private final Secret token;
31 |
32 | /**
33 | * Constructor.
34 | *
35 | * @param scope the credentials scope.
36 | * @param id the credentials id.
37 | * @param description the description of the token.
38 | * @param token the token itself (will be passed through {@link Secret#fromString(String)})
39 | */
40 | @DataBoundConstructor
41 | public PersonalAccessTokenImpl(
42 | @CheckForNull CredentialsScope scope,
43 | @CheckForNull String id,
44 | @CheckForNull String description,
45 | @NonNull String token) {
46 | super(scope, id, description);
47 | this.token = Secret.fromString(token);
48 | }
49 |
50 | /**
51 | * {@inheritDoc}
52 | */
53 | @Override
54 | @NonNull
55 | public Secret getToken() {
56 | return token;
57 | }
58 |
59 | /**
60 | * Our descriptor.
61 | */
62 | @Extension
63 | @Symbol("gitlabPersonalAccessToken")
64 | public static class DescriptorImpl extends CredentialsDescriptor {
65 |
66 | private static final int GITLAB_ACCESS_TOKEN_MINIMAL_LENGTH = 20;
67 |
68 | /**
69 | * {@inheritDoc}
70 | */
71 | @Override
72 | @NonNull
73 | public String getDisplayName() {
74 | return Messages.PersonalAccessTokenImpl_displayName();
75 | }
76 |
77 | /**
78 | * Sanity check for a Gitlab access token.
79 | *
80 | * @param value the personal access token.
81 | * @return the results of the sanity check.
82 | */
83 | @Restricted(NoExternalUse.class) // stapler
84 | @SuppressWarnings("unused")
85 | public FormValidation doCheckToken(@QueryParameter String value) {
86 | Secret secret = Secret.fromString(value);
87 | if (StringUtils.equals(value, secret.getPlainText())) {
88 | if (value.length() < GITLAB_ACCESS_TOKEN_MINIMAL_LENGTH) {
89 | return FormValidation.error(Messages.PersonalAccessTokenImpl_tokenWrongLength());
90 | }
91 | } else if (secret.getPlainText().length() < GITLAB_ACCESS_TOKEN_MINIMAL_LENGTH) {
92 | return FormValidation.error(Messages.PersonalAccessTokenImpl_tokenWrongLength());
93 | }
94 | return FormValidation.ok();
95 | }
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/src/main/java/io/jenkins/plugins/gitlabserverconfig/credentials/helpers/GitLabCredentialMatcher.java:
--------------------------------------------------------------------------------
1 | package io.jenkins.plugins.gitlabserverconfig.credentials.helpers;
2 |
3 | import com.cloudbees.plugins.credentials.Credentials;
4 | import com.cloudbees.plugins.credentials.CredentialsMatcher;
5 | import edu.umd.cs.findbugs.annotations.NonNull;
6 | import io.jenkins.plugins.gitlabserverconfig.credentials.PersonalAccessToken;
7 | import org.jenkinsci.plugins.plaincredentials.StringCredentials;
8 |
9 | public class GitLabCredentialMatcher implements CredentialsMatcher {
10 |
11 | private static final long serialVersionUID = 1;
12 |
13 | @Override
14 | public boolean matches(@NonNull Credentials credentials) {
15 | try {
16 | return credentials instanceof PersonalAccessToken || credentials instanceof StringCredentials;
17 | } catch (Exception e) {
18 | return false;
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/io/jenkins/plugins/gitlabserverconfig/credentials/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * GitLab specific {@link com.cloudbees.plugins.credentials.Credentials} interface and default
3 | * implementation. Note we use an interface so that {@link com.cloudbees.plugins.credentials.CredentialsProvider}
4 | * implementations that store credentials external from {@link jenkins.model.Jenkins} can use {@link
5 | * java.lang.reflect.Proxy} to lazily instantiate {@link hudson.util.Secret} properties on access.
6 | */
7 | package io.jenkins.plugins.gitlabserverconfig.credentials;
8 |
--------------------------------------------------------------------------------
/src/main/java/io/jenkins/plugins/gitlabserverconfig/servers/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Jenkins Global Configuration UI for managing the list of GitLab servers.
3 | */
4 | package io.jenkins.plugins.gitlabserverconfig.servers;
5 |
--------------------------------------------------------------------------------
/src/main/resources/index.jelly:
--------------------------------------------------------------------------------
1 |
2 |
3 | Provides branch source and folder organization functionality for GitLab Repositories in Jenkins
4 |
5 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/BranchDiscoveryTrait/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/BranchDiscoveryTrait/help-branchesAlwaysIncludedRegex.html:
--------------------------------------------------------------------------------
1 |
2 | Regular expression of branches that should always be included regardless of whether a merge request exists or not for those branches.
3 |
4 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/BranchDiscoveryTrait/help-strategyId.html:
--------------------------------------------------------------------------------
1 |
2 | Determines which branches are discovered.
3 |
4 | Only branches that are not also filed as MRs
5 |
6 | If you are discovering origin merge requests, it may not make sense to discover the same
7 | changes both as a
8 | merge request and as a branch.
9 |
10 | Only branches that are also filed as MRs
11 |
12 | This option exists to preserve legacy behaviour when upgrading from older versions of the
13 | plugin.
14 | NOTE: If you have an actual use case for this option please file a merge request against this
15 | text.
16 |
17 | All branches
18 |
19 | Ignores whether the branch is also filed as a merge request and instead discovers all branches
20 | on the
21 | origin project.
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/BranchDiscoveryTrait/help.html:
--------------------------------------------------------------------------------
1 |
2 | Discovers branches on the repository.
3 |
4 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/BuildStatusNameCustomPartTrait/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/BuildStatusNameCustomPartTrait/help-buildStatusNameCustomPart.html:
--------------------------------------------------------------------------------
1 |
2 | Enter a string to customize the status/context name for status updates published to GitLab.
3 | For a branch build the default name would be 'jenkinsci/branch'. With the buildStatusNameCustomPart
4 | 'custom' the name would be 'jenkinsci/custom/branch'.
5 | This allows to have multiple GitLab-Branch-Sources for the same GitLab-project configured.
6 |
7 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/BuildStatusNameCustomPartTrait/help-buildStatusNameOverwrite.html:
--------------------------------------------------------------------------------
1 |
2 | Overwrites the build status name including the jenkinsci default part.
3 | Instead of 'jenkinsci/custom/branch' just 'custom/branch'.
4 |
5 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/BuildStatusNameCustomPartTrait/help.html:
--------------------------------------------------------------------------------
1 |
2 | Customize the pipeline status name used by Jenkins
3 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/ExcludeArchivedRepositoriesTrait/help.html:
--------------------------------------------------------------------------------
1 |
2 | Exclude GitLab repositories that have been archived. If set, no jobs will be created for archived repositories.
3 |
4 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/ForkMergeRequestDiscoveryTrait/TrustEveryone/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ${%blurb}
5 |
6 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/ForkMergeRequestDiscoveryTrait/TrustEveryone/config.properties:
--------------------------------------------------------------------------------
1 | blurb=This option is generally insecure. See help button.
2 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/ForkMergeRequestDiscoveryTrait/TrustMembers/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ${%blurb}
5 |
6 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/ForkMergeRequestDiscoveryTrait/TrustMembers/config.properties:
--------------------------------------------------------------------------------
1 | blurb=This option may be insecure in some environments. See help button.
2 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/ForkMergeRequestDiscoveryTrait/TrustPermission/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ${%blurb}
5 |
6 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/ForkMergeRequestDiscoveryTrait/TrustPermission/config.properties:
--------------------------------------------------------------------------------
1 | blurb=Trusted Members with Developer / Maintainer / Owner access level
2 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/ForkMergeRequestDiscoveryTrait/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/ForkMergeRequestDiscoveryTrait/help-buildMRForksNotMirror.html:
--------------------------------------------------------------------------------
1 |
2 | Add discovery of merge requests where the origin project is a fork of a certain project,
3 | but the target project is not the original forked project.
4 | To be used in case one has a GitLab project which is a fork of another project from another team, in order to isolate artefacts and allow an MR flow.
5 | This means using MRs inside that fork from branches in the fork back to the fork's default branch.
6 | (Implements https://github.com/jenkinsci/gitlab-branch-source-plugin/issues/167)
7 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/ForkMergeRequestDiscoveryTrait/help-strategyId.html:
--------------------------------------------------------------------------------
1 |
2 | Determines how merge requests are discovered:
3 |
4 | Merging the merge request with the current target branch revision
5 | Discover each merge request once with the discovered revision corresponding to the result of
6 | merging with the
7 | current revision of the target branch
8 |
9 | The current merge request revision
10 | Discover each merge request once with the discovered revision corresponding to the merge
11 | request head revision
12 | without merging
13 |
14 | Both the current merge request revision and the merge request merged
15 | with the current target branch revision
16 | Discover each merge request twice. The first discovered revision corresponds to the result
17 | of merging with
18 | the current revision of the target branch in each scan. The second parallel discovered
19 | revision corresponds
20 | to the merge request head revision without merging
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/ForkMergeRequestDiscoveryTrait/help-trust.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | One of the great powers of merge requests is that anyone with read access to a project can fork
4 | it, commit
5 | some changes to their fork and then create a merge request against the original project with
6 | their changes.
7 | There are some files stored in source control that are important. For example, a Jenkinsfile
8 | may contain configuration details to sandbox merge requests in order to mitigate against
9 | malicious merge requests.
10 | In order to protect against a malicious merge request itself modifying the
11 | Jenkinsfile
to remove
12 | the protections, you can define the trust policy for merge requests from forks.
13 |
14 |
15 | Other plugins can extend the available trust policies. The default policies are:
16 |
17 |
18 | Nobody
19 |
20 | Merge requests from forks will all be treated as untrusted. This means that where Jenkins
21 | requires a
22 | trusted file (e.g. Jenkinsfile
) the contents of that file will be retrieved from
23 | the
24 | target branch on the origin project and not from the merge request branch on the fork project.
25 |
26 | Members
27 |
28 | Merge requests from collaborators to the origin project will be treated as trusted, all other
29 | merge
30 | requests from fork repositories will be treated as untrusted.
31 | Note that if credentials used by Jenkins for scanning the project does not have permission to
32 | query the list of contributors to the origin project then only the origin account will be
33 | treated
34 | as trusted - i.e. this will fall back to Nobody
.
35 |
36 | Trusted Members
37 |
38 | Merge requests forks will be treated as trusted if and only if the fork owner has either
39 | Developer or
40 | Maintainer or Owner Access Level in the origin project.
41 | This is the recommended policy.
42 |
43 | Everyone
44 |
45 | All merge requests from forks will be treated as trusted. NOTE: this option
46 | can be dangerous
47 | if used on a public project hosted on a GitLab instance.
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/ForkMergeRequestDiscoveryTrait/help.html:
--------------------------------------------------------------------------------
1 |
2 | Discovers merge requests where the origin project is a fork of the target project.
3 |
4 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/GitLabAvatarTrait/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/GitLabAvatarTrait/help-disableProjectAvatar.html:
--------------------------------------------------------------------------------
1 |
2 | Due to a GitLab bug, sometimes it is not possible to GitLab API to fetch GitLab Avatar for private projects
3 | or when the api doesn't have token access. You may choose to skip avatar for projects if you want to avoid broken
4 | or self generated avatars.
5 |
6 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/GitLabMarkUnstableAsSuccessTrait/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/GitLabSCMNavigator/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/GitLabSCMNavigator/help-credentialsId.html:
--------------------------------------------------------------------------------
1 |
2 | Checkout credentials is only needed for private projects. Add `SSHPrivateKey` or
3 | `Username/Password` to checkout over
4 | SSH remote or HTTPS remote respectively.
5 |
6 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/GitLabSCMNavigator/help-projectOwner.html:
--------------------------------------------------------------------------------
1 |
2 | Specify the namespace which owns your projects. It can be a user, group or subgroup (with full
3 | path). E.g:
4 |
5 | If you want projects from a subgroup `dummysubgroup` inside a group `dummygroup`, then `Owner`
6 | should be dummygroup/dummysubgroup`
7 |
8 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/GitLabSCMNavigator/help-serverName.html:
--------------------------------------------------------------------------------
1 |
2 | Select the GitLab Server where you want the projects to be discovered from.
3 |
4 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSource/config-detail.jelly:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSource/help-credentialsId.html:
--------------------------------------------------------------------------------
1 |
2 | Checkout credentials is only needed for private projects. Add `SSHPrivateKey` or
3 | `Username/Password` to checkout over
4 | SSH remote or HTTPS remote respectively.
5 |
6 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSource/help-projectOwner.html:
--------------------------------------------------------------------------------
1 |
2 | Specify the namespace which owns your projects. It can be a user, a group or a subgroup with full
3 | path. E.g:
4 |
5 | If you want projects from subgroup `a` inside group `b`, then `Owner` should be
6 | b/a
7 |
8 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSource/help-projectPath.html:
--------------------------------------------------------------------------------
1 |
2 | Select the project on which you want to perform the Multibranch Pipeline Job.
3 |
4 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSource/help-serverName.html:
--------------------------------------------------------------------------------
1 |
2 | Select the GitLab Server where you want the projects to be discovered from.
3 |
4 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/HookRegistrationTrait/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/LogCommentTrait/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/LogCommentTrait/help-logSuccess.html:
--------------------------------------------------------------------------------
1 |
2 | Sometimes the user doesn't want to log the builds that succeeded. The trait only enable logging of
3 | failed/aborted
4 | builds by default. Select this option to include logging of successful builds as well.
5 |
6 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/LogCommentTrait/help-sudoUser.html:
--------------------------------------------------------------------------------
1 |
2 | Enter a sudo username of the user you want to comment as on GitLab Server. Remember the token
3 | specified
4 | should have api and sudo access both (which can only be created by your GitLab Server Admin). It
5 | is
6 | recommended to create a dummy user in your GitLab Server with an appropriate username like
7 | `jenkinsadmin` etc. Leave empty if you want use the owner of the project as the commenter.
8 |
9 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/Messages.properties:
--------------------------------------------------------------------------------
1 | BranchSCMHead.Pronoun=Branch
2 | BranchDiscoveryTrait.allBranches=All branches
3 | BranchDiscoveryTrait.authorityDisplayName=Trust origin branches
4 | BranchDiscoveryTrait.displayName=Discover branches
5 | BranchDiscoveryTrait.excludeMRs=Only branches that are not also filed as MRs
6 | BranchDiscoveryTrait.onlyMRs=Only branches that are also filed as MRs
7 | ExcludeArchivedRepositoriesTrait.displayName=Exclude archived repositories
8 | BuildStatusNameCustomPartTrait.displayName=Customize GitLab build status name
9 | ForkMergeRequestDiscoveryTrait.displayName=Discover merge requests from forks
10 | ForkMergeRequestDiscoveryTrait.headAndMerge=Both the current merge request revision and the merge request merged with \
11 | the current target branch revision
12 | ForkMergeRequestDiscoveryTrait.headOnly=The current merge request revision
13 | ForkMergeRequestDiscoveryTrait.mergeOnly=Merging the merge request with the current target branch revision
14 | ForkMergeRequestDiscoveryTrait.contributorsDisplayName=Members
15 | ForkMergeRequestDiscoveryTrait.everyoneDisplayName=Everyone
16 | ForkMergeRequestDiscoveryTrait.nobodyDisplayName=Nobody
17 | ForkMergeRequestDiscoveryTrait.permissionsDisplayName=Trusted Members
18 | GitLabTagSCMHead.Pronoun=Tag
19 | ProjectNamingStrategyTrait.displayName=Project Naming Strategy
20 | ProjectNamingStrategyTrait.fullProjectPath=Full Project Path
21 | ProjectNamingStrategyTrait.contextualProjectPath=Contextual Project Path
22 | ProjectNamingStrategyTrait.simpleProjectPath=Simple Project Path
23 | ProjectNamingStrategyTrait.projectName=Project Name
24 | SubGroupProjectDiscoveryTrait.displayName=Discover subgroup projects
25 | SharedProjectsDiscoveryTrait.displayName=Discover shared projects
26 | TagDiscoveryTrait.authorityDisplayName=Trust origin tags
27 | TagDiscoveryTrait.displayName=Discover tags
28 | GitLabSCMSource.TagCategory=Tags
29 | GitLabBrowser.displayName=GitLab
30 | GitLabLink.displayName=GitLab
31 | GitLabSCMNavigator.description=Scans a GitLab Group (or user account) for all projects matching some defined \
32 | markers.
33 | GitLabSCMNavigator.displayName=GitLab Group
34 | GitLabSCMNavigator.pronoun=GitLab Group
35 | GitLabSCMNavigator.selectedCredentialsMissing=Cannot find currently selected credentials
36 | GitLabSCMNavigator.traitSection_additional=Additional
37 | GitLabSCMNavigator.traitSection_projects=Projects
38 | GitLabSCMNavigator.traitSection_withinRepo=Within project
39 | GitLabSCMSource.ChangeRequestCategory=Merge Requests
40 | GitLabSCMSource.DisplayName=GitLab Project
41 | GitLabSCMSource.Pronoun=GitLab Project
42 | GitLabSCMSource.selectedCredentialsMissing=Cannot find currently selected credentials
43 | GitLabSCMSource.traitSection_additional=Additional
44 | GitLabSCMSource.traitSection_withinRepo=Within project
45 | GitLabSCMSource.UncategorizedCategory=Branches
46 | OriginMergeRequestDiscoveryTrait.authorityDisplayName=Trust origin merge requests
47 | MergeRequestSCMHead.Pronoun=Merge Request
48 | SSHCheckoutTrait.displayName=Checkout over SSH
49 | SSHCheckoutTrait.incompatibleCredentials=The currently configured credentials are incompatible with this behaviour
50 | SSHCheckoutTrait.missingCredentials=The currently configured credentials cannot be found
51 | SSHCheckoutTrait.useAgentKey=- use build agent''s key -
52 | HookRegistrationTrait.disable=Disable {0} management
53 | HookRegistrationTrait.displayName=Override GitLab hook management modes
54 | HookRegistrationTrait.useItem=Use Item credentials for {0} management
55 | HookRegistrationTrait.useSystem=Use System credentials for {0} management mode (default)
56 | GitLabSkipNotificationsTrait.displayName=Skip pipeline status notifications
57 | GitLabAvatarTrait.displayName=Disable GitLab project avatars
58 | LogCommentTrait.displayName=Log build status as comment on GitLab
59 | TriggerMRCommentTrait.displayName=Trigger build on merge request comment
60 | GitLabWebHookCause.ShortDescription.Push_noUser=Started by GitLab push
61 | GitLabWebHookCause.ShortDescription.Push=Started by GitLab push by {0}
62 | GitLabWebHookCause.ShortDescription.MergeRequestHook=Triggered by GitLab Merge Request #{0}: {1} => {2}
63 | WebhookListenerBuildConditionsTrait.displayName=Webhook Listener Conditions
64 | GitLabMarkUnstableAsSuccessTrait.displayName=Mark unstable build as successful on Gitlab
65 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/OriginMergeRequestDiscoveryTrait/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/OriginMergeRequestDiscoveryTrait/help-strategyId.html:
--------------------------------------------------------------------------------
1 |
2 | Determines how merge requests are discovered:
3 |
4 | Merging the merge request with the current target branch revision
5 | Discover each merge request once with the discovered revision corresponding to the result of
6 | merging with the
7 | current revision of the target branch
8 |
9 | The current merge request revision
10 | Discover each merge request once with the discovered revision corresponding to the merge
11 | request head revision
12 | without merging
13 |
14 | Both the current merge request revision and the merge request merged
15 | with the current target branch revision
16 | Discover each merge request twice. The first discovered revision corresponds to the result
17 | of merging with
18 | the current revision of the target branch in each scan. The second parallel discovered
19 | revision corresponds
20 | to the merge request head revision without merging
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/OriginMergeRequestDiscoveryTrait/help.html:
--------------------------------------------------------------------------------
1 |
2 | Discovers merge requests where the origin project is the same as the target project.
3 |
4 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/ProjectNamingStrategyTrait/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 | Changing naming strategy will cause projects and build logs to be destroyed
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/ProjectNamingStrategyTrait/help-strategyId.html:
--------------------------------------------------------------------------------
1 |
2 | Determines the naming convention of projects
3 |
4 | Full Project Path
5 |
6 | This option will use the full project path for the group and project.
7 | Examples:
8 |
9 | my-group/ my-project
10 | my-group/ other-project
11 | my-group/my-subgroup/ third-project
12 |
13 |
14 | Project Name
15 |
16 | This option will use project names from GitLab project name.
17 | This is the "friendly" name of the project and could contain capitalization, spaces or other special characters.
18 | Examples:
19 |
20 | My Project
21 | Other project
22 | My Subgroup / Third project
23 |
24 |
25 | Contextual Project Path
26 |
27 | This option will use the project path with nested groups, but not the top-level owner
segment specified on the Jenkins pipeline.
28 | Examples where owner
on pipeline has been set to "my-group":
29 |
30 | my-project
31 | other-project
32 | my-subgroup/ third-project
33 |
34 |
35 | Simple Project Path
36 |
37 | This option will use the project path with no parent group information added.
38 | Examples:
39 |
40 | my-project
41 | other-project
42 | third-project
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/ProjectNamingStrategyTrait/help.html:
--------------------------------------------------------------------------------
1 |
2 | Naming convention of projects
3 |
4 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/SSHCheckoutTrait/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/SSHCheckoutTrait/help-credentialsId.html:
--------------------------------------------------------------------------------
1 |
2 | Credentials used to check out sources. Must be a SSH key based credential.
3 |
4 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/SSHCheckoutTrait/help.html:
--------------------------------------------------------------------------------
1 |
2 | By default the discovered branches / merge requests will all use the same username / password
3 | credentials
4 | that were used for discovery when checking out sources. This means that the checkout will be using
5 | the
6 |
https://
protocol for the Git repository.
7 |
8 | This behaviour allows you to select the SSH private key to be used for checking out sources,
9 | which will
10 | consequently force the checkout to use the ssh://
protocol.
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/SharedProjectsDiscoveryTrait/help.html:
--------------------------------------------------------------------------------
1 |
2 | Discovers all shared projects for an owner (Group/Subgroup) but not User.
3 |
4 |
5 | NOTE this trait used to be enabled by default,
6 | but it is potentially dangerous to allow repositories that are controlled by another group
7 | to execute on the Jenkins controller/folder.
8 | So the default behavior was changed and this trait is now optional.
9 |
10 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/SubGroupProjectDiscoveryTrait/help.html:
--------------------------------------------------------------------------------
1 |
2 | Discovers all subgroup projects for an owner (Group/Subgroup) but not User.
3 |
4 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/TriggerMRCommentTrait/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/TriggerMRCommentTrait/help-commentBody.html:
--------------------------------------------------------------------------------
1 |
2 | Add comment body you want to use to instruct Jenkins CI to rebuild the MR
3 |
4 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/TriggerMRCommentTrait/help-onlyTrustedMembers.html:
--------------------------------------------------------------------------------
1 |
2 | If checked only trusted members of project can trigger MR. Trusted members mean members with Developer/Maintainer access (also includes inherited from ancestor groups) in the project.
3 | You may want to disable this option because trusted members do not include members inherited from shared group (there is no way to get it from GitLabApi as of GitLab 13.0.0).
4 | If disabled, MR comment trigger can be done by any user having access to your project.
5 |
6 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/WebhookListenerBuildConditionsTrait/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/WebhookListenerBuildConditionsTrait/help-alwaysIgnoreNonCodeRelatedUpdates.html:
--------------------------------------------------------------------------------
1 |
2 | GitLab will send a webhook to Jenkins when there are updates to the MR including title changes, labels removed/added, etc. Enabling this option will prevent a build running if the cause was one of these updates.
3 |
4 | Note: these settings do not have any impact on build from comment settings.
5 |
6 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabBrowser/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabBrowser/help-projectUrl.html:
--------------------------------------------------------------------------------
1 |
2 | Specify the HTTP URL for this project's GitLab page. The URL needs to include the owner and
3 | project so, for
4 | example, if the GitLab server is https://gitLab.example.com
then the URL for bob's
5 | skunkworks
6 | project might be https://gitLab.example.com/bob/skunkworks
7 |
8 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabBrowser/help.html:
--------------------------------------------------------------------------------
1 |
2 | Specify the HTTP URL for this project's GitLab page so that links to changes can be automatically generated by Jenkins.
3 | The URL needs to include the owner and project.
4 | If the GitLab server is https://gitLab.example.com
then the URL for bob's skunkworks
5 | project might be https://gitLab.example.com/bob/skunkworks
.
6 |
7 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabserverconfig/credentials/Messages.properties:
--------------------------------------------------------------------------------
1 | PersonalAccessTokenImpl.displayName=GitLab Personal Access Token
2 | PersonalAccessTokenImpl.tokenRequired=Token required
3 | PersonalAccessTokenImpl.tokenWrongLength=Token should be at least 20 characters long
4 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabserverconfig/credentials/PersonalAccessTokenImpl/credentials.jelly:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServer/config.groovy:
--------------------------------------------------------------------------------
1 | package io.jenkins.plugins.gitlabserverconfig.servers.GitLabServer
2 |
3 | import io.jenkins.plugins.gitlabserverconfig.servers.GitLabServer
4 | import lib.CredentialsTagLib
5 | import lib.FormTagLib
6 | import org.apache.commons.lang.RandomStringUtils;
7 |
8 | def f = namespace(FormTagLib)
9 | def c = namespace(CredentialsTagLib)
10 |
11 | f.entry(title: _("Display Name"), field: "name", "description": "A unique name for the server") {
12 | f.textbox(default: String.format("gitlab-%s", RandomStringUtils.randomNumeric(GitLabServer.SHORT_NAME_LENGTH)))
13 | }
14 |
15 | f.entry(title: _("Server URL"), field: "serverUrl", "description": "The url to the GitLab server") {
16 | f.textbox(default: GitLabServer.GITLAB_SERVER_URL, checkMethod: 'post')
17 | }
18 |
19 | f.entry(title: _("Credentials"), field: "credentialsId", "description": "The Personal Access Token for GitLab APIs access") {
20 | c.select(context: app)
21 | }
22 |
23 | f.entry(title: _("Web Hook"), field: "manageWebHooks", "description": "Do you want to automatically manage GitLab Web Hooks on Jenkins Server?") {
24 | f.checkbox(title: _("Manage Web Hooks"))
25 | }
26 |
27 | f.entry(title: _("System Hook"), field: "manageSystemHooks", "description": "Do you want to automatically manage GitLab System Hooks on Jenkins Server?") {
28 | f.checkbox(title: _("Manage System Hooks"))
29 | }
30 |
31 | f.entry(title: _("Secret Token"), field: "webhookSecretCredentialsId", "description": "The secret token used while setting up hook url in the GitLab server") {
32 | c.select(context: app)
33 | }
34 |
35 | f.entry(title: _("Root URL for hooks"), field: "hooksRootUrl", "description": "Jenkins root URL to use in hooks URL (if different from the public Jenkins root URL)") {
36 | f.textbox()
37 | }
38 |
39 | f.advanced() {
40 | f.entry(title: _("Immediate Web Hook trigger"), field: "immediateHookTrigger", "description": "Trigger a build immediately on a GitLab Web Hook trigger") {
41 | f.checkbox(title: _("Immediate Web Hook trigger"))
42 | }
43 | f.entry(title: _("Web Hook trigger delay"), field: "hookTriggerDelay", "description": "Delay in seconds to be used for GitLab Web Hook build triggers (defaults to GitLab cache timeout)") {
44 | f.textbox()
45 | }
46 | }
47 |
48 | f.validateButton(
49 | title: _("Test connection"),
50 | progress: _("Testing.."),
51 | method: "testConnection",
52 | with: "serverUrl,credentialsId"
53 | )
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServer/help-credentialsId.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | You can create your own
personal
4 | access token .
5 |
6 |
7 | Token should be registered with scopes:
8 |
9 | api - For read/write access to the API, including all groups and projects
10 | repo - For read-only access to the authenticated user's profile through the /user API
11 | endpoint, which includes username, public email, and full name
12 |
13 |
14 |
15 | In Jenkins, create a token credential as «
GitLab Personal Access Token » or any
16 | «
StringCredentials » type credential (e.g. «
"Secret text" » provided by
17 |
Plain Credentials plugin or
18 | «
"Vault Secret Text Credential" » provided by
19 |
HashiCorp Vault plugin ).
20 | Human-readable id and description is recommended.
21 |
22 |
23 |
24 | If you have an existing GitLab login and password you can convert it to a token automatically
25 | with the help of «Manage additional GitLab actions » in Advanced section of
26 | GitLab Servers.
27 |
28 |
29 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServer/help-genButton.html:
--------------------------------------------------------------------------------
1 |
2 | Use this button to generate a new secret token to be used during hook creation. If older jobs exist they need to be rescanned to update existing hook.
3 |
4 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServer/help-hookTriggerDelay.html:
--------------------------------------------------------------------------------
1 |
2 | Set non-empty if you want to use a GitLab Webhook trigger delay different from
3 | GitLab cache timeout.
4 | Note that setting this to a value smaller than GitLab cache timeout will result
5 | in GitLab repository changes not being detected and builds not being triggered reliably.
6 |
7 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServer/help-hooksRootUrl.html:
--------------------------------------------------------------------------------
1 |
2 | The Jenkins root URL (for instance https://something:8443/jenkins/
) to use in hooks URL.
3 | This is only required when the globally configured public URL for Jenkins can not be reached from your GitLab server.
4 |
5 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServer/help-immediateHookTrigger.html:
--------------------------------------------------------------------------------
1 |
2 | Select this option if you want to immediately query gitlab for modifications when a
3 | web hook trigger is received.
4 | Using this option lets you start a build a soon as possible and rely on the "Web Hook trigger delay"
5 | value as a fallback in case gitlab's cache did not return the modifications.
6 |
7 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServer/help-manageSystemHooks.html:
--------------------------------------------------------------------------------
1 |
2 | Select this option if you want to setup System Hooks on your Jenkins instance. Remember Jenkins
3 | can register
4 | System Hook in GitLab Server only if the authenticated token has Admin access.
5 |
6 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServer/help-manageWebHooks.html:
--------------------------------------------------------------------------------
1 |
2 | Selecting this option will enable the automatic management of web hooks for all items that use the
3 | GitLab Server
4 | endpoint, with the exception of those items that have explicitly opted out of hook management.
5 | When this option is not selected, individual items can still opt in to hook management provided
6 | the credentials
7 | those items have been configured with have permission to manage the required hooks.
8 |
9 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServer/help-name.html:
--------------------------------------------------------------------------------
1 |
2 | A human friendly and unique name for this GitLab server. If left blank, generates a unique default
3 | name.
4 |
5 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServer/help-serverUrl.html:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServer/help-webhookSecretCredentialsId.html:
--------------------------------------------------------------------------------
1 |
2 | The secret token is required to authenticate the webhook payloads received from a GitLab Server. Use generate secret token from Advanced options or use your own. If you are an old plugin user and did not set a secret token previously and want the secret token to be applied to the hooks of your existing jobs, you can add the secret token and rescan your jobs. Existing hooks with new secret token will be applied.
3 |
4 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServers/config.groovy:
--------------------------------------------------------------------------------
1 | package io.jenkins.plugins.gitlabserverconfig.servers.GitLabServers
2 |
3 | import lib.FormTagLib
4 |
5 | def f = namespace(FormTagLib)
6 |
7 | f.section(title: descriptor.displayName) {
8 |
9 | f.entry(title: _("GitLab Servers")) {
10 | f.repeatableHeteroProperty(
11 | field: "servers",
12 | hasHeader: "true",
13 | addCaption: _("Add GitLab Server")
14 | )
15 | }
16 | f.advanced() {
17 | f.entry() {
18 | f.entry(title: _("Additional actions"), help: descriptor.getHelpFile('additional')) {
19 | f.hetero_list(items: [],
20 | addCaption: _("Manage additional GitLab actions"),
21 | name: "actions",
22 | oneEach: "true", hasHeader: "true", descriptors: instance.actions())
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServers/help-additional.html:
--------------------------------------------------------------------------------
1 |
2 | Additional actions can help you with some routines. For example, you can convert your existing
3 | login + password
4 | (stored in credentials or directly) to a GitLab Personal Access Token.
5 |
6 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabserverconfig/servers/Messages.properties:
--------------------------------------------------------------------------------
1 | GitLabServers.displayName=GitLab
2 | GitLabServer.displayName=GitLab Server
3 | GitLabServer.hookManagementAs=Hook management will be performed as {0}
4 | GitLabServer.validateInterrupted=Interrupted while trying to validate credentials
5 | GitLabServer.versionInterrupted=Interrupted while trying to determine server version
6 | GitLabServer.invalidUrl=Invalid GitLab Server URL: {0}
7 | GitLabServer.serverVersion=GitLab Version: {0}
8 | GitLabServer.failedValidation=Failed to validate the account {0}
9 | GitLabServer.credentialsNotResolved=Cannot resolve suitable credentials with id: {0}
10 | GitLabServer.advancedSectionForFuture=Advanced configurations will be added in later release
11 |
--------------------------------------------------------------------------------
/src/main/resources/io/jenkins/plugins/gitlabserverconfig/servers/helpers/GitLabPersonalAccessTokenCreator/config.groovy:
--------------------------------------------------------------------------------
1 | package io.jenkins.plugins.gitlabserverconfig.servers.helpers.GitLabPersonalAccessTokenCreator
2 |
3 | import io.jenkins.plugins.gitlabserverconfig.servers.GitLabServer
4 | import lib.CredentialsTagLib
5 | import lib.FormTagLib
6 |
7 |
8 | def f = namespace(FormTagLib);
9 | def c = namespace(CredentialsTagLib)
10 |
11 | f.entry(title: _("GitLab Server URL"), field: "serverUrl",
12 | help: app.getDescriptor(GitLabServer.class)?.getHelpFile("serverUrl")) {
13 | f.textbox(default: GitLabServer.GITLAB_SERVER_URL)
14 | }
15 |
16 | f.radioBlock(checked: true, name: "credentials", value: "plugin", title: "From credentials") {
17 | f.entry(title: _("Credentials"), field: "credentialsId") {
18 | c.select(context: app, includeUser: true, expressionAllowed: false)
19 | }
20 |
21 | f.block() {
22 | f.validateButton(
23 | title: _("Create token credentials"),
24 | progress: _("Creating..."),
25 | method: "createTokenByCredentials",
26 | with: "serverUrl,credentialsId"
27 | )
28 | }
29 | }
30 |
31 | f.radioBlock(checked: false, name: "credentials", value: "manually", title: "From login and password") {
32 |
33 | f.entry(title: _("Username"), field: "login") {
34 | f.textbox()
35 | }
36 |
37 | f.entry(title: _("Password"), field: "password") {
38 | f.password()
39 | }
40 |
41 | f.block() {
42 | f.validateButton(
43 | title: _("Create token credentials"),
44 | progress: _("Creating..."),
45 | method: "createTokenByPassword",
46 | with: "serverUrl,login,password"
47 | )
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/webapp/images/gitlab-branch.svg:
--------------------------------------------------------------------------------
1 |
2 | Git Branch
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/main/webapp/images/gitlab-commit.svg:
--------------------------------------------------------------------------------
1 |
2 | Git Commit
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/main/webapp/images/gitlab-logo.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
17 | gitlab-icon-rgb
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/src/main/webapp/images/gitlab-mr.svg:
--------------------------------------------------------------------------------
1 |
2 | Git Pull Request
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/main/webapp/images/gitlab-project.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | image/svg+xml
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/main/webapp/images/gitlab-tag.svg:
--------------------------------------------------------------------------------
1 |
2 | Pricetag
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/test/java/io/jenkins/plugins/gitlabbranchsource/GitLabHookCreatorParameterizedTest.java:
--------------------------------------------------------------------------------
1 | package io.jenkins.plugins.gitlabbranchsource;
2 |
3 | import static org.hamcrest.Matchers.containsString;
4 | import static org.hamcrest.Matchers.not;
5 | import static org.hamcrest.core.Is.is;
6 | import static org.junit.Assert.assertThat;
7 |
8 | import io.jenkins.plugins.gitlabserverconfig.servers.GitLabServer;
9 | import java.util.Arrays;
10 | import jenkins.model.JenkinsLocationConfiguration;
11 | import org.junit.ClassRule;
12 | import org.junit.Test;
13 | import org.junit.runner.RunWith;
14 | import org.junit.runners.Parameterized;
15 | import org.junit.runners.Parameterized.Parameters;
16 | import org.jvnet.hudson.test.JenkinsRule;
17 |
18 | @RunWith(Parameterized.class)
19 | public class GitLabHookCreatorParameterizedTest {
20 |
21 | @ClassRule
22 | public static JenkinsRule r = new JenkinsRule();
23 |
24 | private final String jenkinsUrl;
25 | private final boolean hookType;
26 | private final String expectedPath;
27 |
28 | @Parameters(name = "check {0}")
29 | public static Iterable data() {
30 | return Arrays.asList(new Object[][] {
31 | {"intranet.local:8080", false, "/gitlab-systemhook/post"},
32 | {"intranet.local", true, "/gitlab-webhook/post"},
33 | {"www.mydomain.com:8000", true, "/gitlab-webhook/post"},
34 | {"www.mydomain.com", false, "/gitlab-systemhook/post"},
35 | {"www.mydomain.com/jenkins", true, "/gitlab-webhook/post"}
36 | });
37 | }
38 |
39 | public GitLabHookCreatorParameterizedTest(String jenkinsUrl, boolean hookType, String expectedPath) {
40 | this.jenkinsUrl = jenkinsUrl;
41 | this.hookType = hookType;
42 | this.expectedPath = expectedPath;
43 | }
44 |
45 | @Test
46 | public void hookUrl() {
47 | Arrays.asList("http://", "https://").forEach(proto -> {
48 | String expected = proto + jenkinsUrl + expectedPath;
49 | JenkinsLocationConfiguration.get().setUrl(proto + jenkinsUrl);
50 | String hookUrl = GitLabHookCreator.getHookUrl(null, hookType);
51 | GitLabHookCreator.checkURL(hookUrl);
52 | assertThat(hookUrl.replaceAll(proto, ""), not(containsString("//")));
53 | assertThat(hookUrl, is(expected));
54 | });
55 | }
56 |
57 | @Test
58 | public void hookUrlFromCustomRootUrl() {
59 | Arrays.asList("http://", "https://").forEach(proto -> {
60 | String expected = proto + jenkinsUrl + expectedPath;
61 | JenkinsLocationConfiguration.get().setUrl("http://whatever");
62 | GitLabServer server = new GitLabServer("https://gitlab.com", "GitLab", null);
63 | server.setHooksRootUrl(proto + jenkinsUrl);
64 | String hookUrl = GitLabHookCreator.getHookUrl(server, hookType);
65 | GitLabHookCreator.checkURL(hookUrl);
66 | assertThat(hookUrl.replaceAll(proto, ""), not(containsString("//")));
67 | assertThat(hookUrl, is(expected));
68 | });
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/test/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSourceDeserializationTest.java:
--------------------------------------------------------------------------------
1 | package io.jenkins.plugins.gitlabbranchsource;
2 |
3 | import static org.junit.Assert.assertEquals;
4 | import static org.junit.Assert.assertNotNull;
5 |
6 | import java.lang.reflect.Field;
7 | import jenkins.branch.BranchSource;
8 | import jenkins.scm.api.SCMSource;
9 | import org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject;
10 | import org.junit.Rule;
11 | import org.junit.Test;
12 | import org.jvnet.hudson.test.RestartableJenkinsRule;
13 |
14 | public class GitLabSCMSourceDeserializationTest {
15 |
16 | private static final String PROJECT_NAME = "project";
17 | private static final String SOURCE_ID = "id";
18 |
19 | @Rule
20 | public final RestartableJenkinsRule plan = new RestartableJenkinsRule();
21 |
22 | @Test
23 | public void afterRestartingJenkinsTransientFieldsAreNotNull() throws Exception {
24 | plan.then(j -> {
25 | GitLabSCMSourceBuilder sb =
26 | new GitLabSCMSourceBuilder(SOURCE_ID, "server", "creds", "po", "group/project", "project");
27 | WorkflowMultiBranchProject project = j.createProject(WorkflowMultiBranchProject.class, PROJECT_NAME);
28 | project.getSourcesList().add(new BranchSource(sb.build()));
29 | });
30 |
31 | plan.then(j -> {
32 | SCMSource source = j.getInstance().getAllItems(WorkflowMultiBranchProject.class).stream()
33 | .filter(p -> PROJECT_NAME.equals(p.getName()))
34 | .map(p -> p.getSCMSource(SOURCE_ID))
35 | .findFirst()
36 | .get();
37 |
38 | Class extends SCMSource> clazz = source.getClass();
39 | Field mergeRequestContributorCache = clazz.getDeclaredField("mergeRequestContributorCache");
40 | mergeRequestContributorCache.setAccessible(true);
41 | Field mergeRequestMetadataCache = clazz.getDeclaredField("mergeRequestMetadataCache");
42 | mergeRequestMetadataCache.setAccessible(true);
43 | assertNotNull(mergeRequestMetadataCache.get(source));
44 | assertNotNull(mergeRequestContributorCache.get(source));
45 | });
46 | }
47 |
48 | @Test
49 | public void projectIdSurvivesConfigRoundtrip() {
50 | plan.then(j -> {
51 | GitLabSCMSourceBuilder sb =
52 | new GitLabSCMSourceBuilder(SOURCE_ID, "server", "creds", "po", "group/project", "project");
53 | WorkflowMultiBranchProject project = j.createProject(WorkflowMultiBranchProject.class, PROJECT_NAME);
54 | GitLabSCMSource source = sb.build();
55 | project.getSourcesList().add(new BranchSource(source));
56 | long p = 42;
57 | source.setProjectId(p);
58 | j.configRoundtrip(project);
59 |
60 | WorkflowMultiBranchProject item =
61 | j.jenkins.getItemByFullName(PROJECT_NAME, WorkflowMultiBranchProject.class);
62 | assertNotNull(item);
63 | GitLabSCMSource scmSource = (GitLabSCMSource) item.getSCMSource(SOURCE_ID);
64 | assertNotNull(scmSource);
65 | assertEquals(Long.valueOf(p), scmSource.getProjectId());
66 | });
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/test/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSourceTest.java:
--------------------------------------------------------------------------------
1 | package io.jenkins.plugins.gitlabbranchsource;
2 |
3 | import static org.junit.jupiter.api.Assertions.assertEquals;
4 | import static org.mockito.ArgumentMatchers.any;
5 | import static org.mockito.ArgumentMatchers.anyString;
6 |
7 | import hudson.model.TaskListener;
8 | import hudson.security.AccessControlled;
9 | import hudson.util.StreamTaskListener;
10 | import io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper;
11 | import io.jenkins.plugins.gitlabserverconfig.servers.GitLabServer;
12 | import io.jenkins.plugins.gitlabserverconfig.servers.GitLabServers;
13 | import java.io.ByteArrayOutputStream;
14 | import java.io.IOException;
15 | import java.nio.charset.StandardCharsets;
16 | import java.util.Arrays;
17 | import java.util.Set;
18 | import jenkins.branch.BranchSource;
19 | import jenkins.scm.api.SCMHead;
20 | import org.gitlab4j.api.GitLabApi;
21 | import org.gitlab4j.api.GitLabApiException;
22 | import org.gitlab4j.api.MergeRequestApi;
23 | import org.gitlab4j.api.ProjectApi;
24 | import org.gitlab4j.api.RepositoryApi;
25 | import org.gitlab4j.api.models.Project;
26 | import org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject;
27 | import org.junit.ClassRule;
28 | import org.junit.Test;
29 | import org.jvnet.hudson.test.JenkinsRule;
30 | import org.mockito.MockedStatic;
31 | import org.mockito.Mockito;
32 |
33 | public class GitLabSCMSourceTest {
34 |
35 | private static final String SERVER = "server";
36 | private static final String PROJECT_NAME = "project";
37 | private static final String SOURCE_ID = "id";
38 |
39 | @ClassRule
40 | public static JenkinsRule j = new JenkinsRule();
41 |
42 | @Test
43 | public void retrieveMRWithEmptyProjectSettings() throws GitLabApiException, IOException, InterruptedException {
44 | GitLabApi gitLabApi = Mockito.mock(GitLabApi.class);
45 | ProjectApi projectApi = Mockito.mock(ProjectApi.class);
46 | RepositoryApi repoApi = Mockito.mock(RepositoryApi.class);
47 | MergeRequestApi mrApi = Mockito.mock(MergeRequestApi.class);
48 | Mockito.when(gitLabApi.getProjectApi()).thenReturn(projectApi);
49 | Mockito.when(gitLabApi.getMergeRequestApi()).thenReturn(mrApi);
50 | Mockito.when(gitLabApi.getRepositoryApi()).thenReturn(repoApi);
51 | Mockito.when(projectApi.getProject(any())).thenReturn(new Project());
52 | try (MockedStatic utilities = Mockito.mockStatic(GitLabHelper.class)) {
53 | utilities
54 | .when(() -> GitLabHelper.apiBuilder(any(AccessControlled.class), anyString()))
55 | .thenReturn(gitLabApi);
56 | GitLabServers.get().addServer(new GitLabServer("", SERVER, ""));
57 | GitLabSCMSourceBuilder sb =
58 | new GitLabSCMSourceBuilder(SOURCE_ID, SERVER, "creds", "po", "group/project", "project");
59 | WorkflowMultiBranchProject project = j.createProject(WorkflowMultiBranchProject.class, PROJECT_NAME);
60 | BranchSource source = new BranchSource(sb.build());
61 | source.getSource()
62 | .setTraits(Arrays.asList(new BranchDiscoveryTrait(0), new OriginMergeRequestDiscoveryTrait(1)));
63 | project.getSourcesList().add(source);
64 | ByteArrayOutputStream out = new ByteArrayOutputStream();
65 | final TaskListener listener = new StreamTaskListener(out, StandardCharsets.UTF_8);
66 | Set scmHead = source.getSource().fetch(listener);
67 | assertEquals(0, scmHead.size());
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/test/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabHelperTest.java:
--------------------------------------------------------------------------------
1 | package io.jenkins.plugins.gitlabbranchsource.helpers;
2 |
3 | import static org.hamcrest.MatcherAssert.assertThat;
4 | import static org.hamcrest.Matchers.is;
5 |
6 | import io.jenkins.plugins.gitlabserverconfig.servers.GitLabServer;
7 | import org.junit.Test;
8 |
9 | public class GitLabHelperTest {
10 |
11 | @Test
12 | public void server_url_does_not_have_trailing_slash() {
13 | assertThat(GitLabHelper.getServerUrl(null), is("https://gitlab.com"));
14 |
15 | GitLabServer server1 = new GitLabServer("https://company.com/gitlab/", "comp_server", "1245");
16 | assertThat(GitLabHelper.getServerUrl(server1), is("https://company.com/gitlab"));
17 |
18 | GitLabServer server2 = new GitLabServer("https://gitlab.example.org", "", "pw-id");
19 | assertThat(GitLabHelper.getServerUrl(server2), is("https://gitlab.example.org"));
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/test/java/io/jenkins/plugins/gitlabserverconfig/casc/ConfigurationAsCodeTest.java:
--------------------------------------------------------------------------------
1 | package io.jenkins.plugins.gitlabserverconfig.casc;
2 |
3 | import static io.jenkins.plugins.casc.misc.Util.getUnclassifiedRoot;
4 | import static io.jenkins.plugins.casc.misc.Util.toStringFromYamlFile;
5 | import static io.jenkins.plugins.casc.misc.Util.toYamlString;
6 | import static org.hamcrest.MatcherAssert.assertThat;
7 | import static org.hamcrest.Matchers.hasSize;
8 | import static org.hamcrest.Matchers.is;
9 | import static org.hamcrest.Matchers.matchesPattern;
10 | import static org.hamcrest.Matchers.not;
11 |
12 | import com.cloudbees.plugins.credentials.CredentialsProvider;
13 | import hudson.security.ACL;
14 | import io.jenkins.plugins.casc.ConfigurationContext;
15 | import io.jenkins.plugins.casc.ConfiguratorRegistry;
16 | import io.jenkins.plugins.casc.misc.ConfiguredWithCode;
17 | import io.jenkins.plugins.casc.misc.JenkinsConfiguredWithCodeRule;
18 | import io.jenkins.plugins.casc.model.CNode;
19 | import io.jenkins.plugins.gitlabserverconfig.credentials.PersonalAccessTokenImpl;
20 | import io.jenkins.plugins.gitlabserverconfig.servers.GitLabServer;
21 | import io.jenkins.plugins.gitlabserverconfig.servers.GitLabServers;
22 | import java.util.Collections;
23 | import java.util.List;
24 | import org.junit.ClassRule;
25 | import org.junit.Test;
26 |
27 | public class ConfigurationAsCodeTest {
28 |
29 | @ClassRule
30 | @ConfiguredWithCode("configuration-as-code.yml")
31 | public static JenkinsConfiguredWithCodeRule j = new JenkinsConfiguredWithCodeRule();
32 |
33 | @Test
34 | public void should_support_configuration_as_code() {
35 | List servers = GitLabServers.get().getServers();
36 | assertThat(servers.size(), is(1));
37 | GitLabServer server = servers.get(0);
38 | assertThat(server.getServerUrl(), is("https://gitlab.com"));
39 | assertThat(server.getName(), matchesPattern("gitlab-[0-9]{4}"));
40 | assertThat(server.isManageWebHooks(), is(true));
41 | assertThat(server.isManageSystemHooks(), is(true));
42 | assertThat(server.getHooksRootUrl(), is("https://jenkins.intranet/"));
43 |
44 | List credentials = CredentialsProvider.lookupCredentials(
45 | PersonalAccessTokenImpl.class, j.jenkins, ACL.SYSTEM, Collections.emptyList());
46 | assertThat(credentials, hasSize(1));
47 | final PersonalAccessTokenImpl credential = credentials.get(0);
48 | assertThat(credential.getToken().getPlainText(), is("glpat-XfsqZvVtAx5YCph5bq3r"));
49 | assertThat(credential.getToken().getEncryptedValue(), is(not("glpat-XfsqZvVtAx5YCph5bq3r")));
50 | }
51 |
52 | @Test
53 | public void should_support_configuration_export() throws Exception {
54 | ConfiguratorRegistry registry = ConfiguratorRegistry.get();
55 | ConfigurationContext context = new ConfigurationContext(registry);
56 | CNode gitLabServers = getUnclassifiedRoot(context).get("gitLabServers");
57 |
58 | String exported = toYamlString(gitLabServers);
59 |
60 | String expected = toStringFromYamlFile(this, "expected_output.yml");
61 |
62 | assertThat(exported, matchesPattern(expected));
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/test/java/io/jenkins/plugins/gitlabserverconfig/credentials/PersonalAccessTokenImplTest.java:
--------------------------------------------------------------------------------
1 | package io.jenkins.plugins.gitlabserverconfig.credentials;
2 |
3 | import com.cloudbees.plugins.credentials.Credentials;
4 | import com.cloudbees.plugins.credentials.CredentialsScope;
5 | import hudson.model.AbstractProject;
6 | import hudson.tasks.BuildStepDescriptor;
7 | import hudson.tasks.Builder;
8 | import org.junit.ClassRule;
9 | import org.junit.Test;
10 | import org.jvnet.hudson.test.JenkinsRule;
11 | import org.jvnet.hudson.test.TestExtension;
12 | import org.kohsuke.stapler.DataBoundConstructor;
13 |
14 | public class PersonalAccessTokenImplTest {
15 |
16 | @ClassRule
17 | public static JenkinsRule j = new JenkinsRule();
18 |
19 | @Test
20 | public void configRoundtrip() throws Exception {
21 | PersonalAccessTokenImpl expected = new PersonalAccessTokenImpl(
22 | CredentialsScope.GLOBAL, "magic-id", "configRoundtrip", "sAf_Xasnou47yxoAsC");
23 | CredentialsBuilder builder = new CredentialsBuilder(expected);
24 | j.configRoundtrip(builder);
25 | j.assertEqualDataBoundBeans(expected, builder.credentials);
26 | }
27 |
28 | /**
29 | * Helper for {@link #configRoundtrip()}.
30 | */
31 | public static class CredentialsBuilder extends Builder {
32 |
33 | public final Credentials credentials;
34 |
35 | @DataBoundConstructor
36 | public CredentialsBuilder(Credentials credentials) {
37 | this.credentials = credentials;
38 | }
39 |
40 | @TestExtension
41 | public static class DescriptorImpl extends BuildStepDescriptor {
42 |
43 | @Override
44 | public String getDisplayName() {
45 | return "CredentialsBuilder";
46 | }
47 |
48 | @SuppressWarnings("rawtypes")
49 | @Override
50 | public boolean isApplicable(Class extends AbstractProject> jobType) {
51 | return true;
52 | }
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/test/java/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServerTest.java:
--------------------------------------------------------------------------------
1 | package io.jenkins.plugins.gitlabserverconfig.servers;
2 |
3 | import static org.hamcrest.CoreMatchers.nullValue;
4 | import static org.hamcrest.CoreMatchers.startsWith;
5 | import static org.hamcrest.MatcherAssert.assertThat;
6 | import static org.hamcrest.Matchers.is;
7 | import static org.junit.Assert.assertEquals;
8 |
9 | import java.io.IOException;
10 | import org.apache.http.HttpStatus;
11 | import org.htmlunit.html.HtmlPage;
12 | import org.junit.ClassRule;
13 | import org.junit.Test;
14 | import org.jvnet.hudson.test.Issue;
15 | import org.jvnet.hudson.test.JenkinsRule;
16 | import org.jvnet.hudson.test.JenkinsRule.WebClient;
17 | import org.xml.sax.SAXException;
18 |
19 | public class GitLabServerTest {
20 |
21 | @ClassRule
22 | public static JenkinsRule j = new JenkinsRule();
23 |
24 | @Test
25 | public void testFixEmptyAndTrimOne() throws Exception {
26 | GitLabServer server = new GitLabServer("https://gitlab.com", "default", null);
27 | server.setHooksRootUrl("https://myhooks/");
28 | assertThat(server.getName(), is("default"));
29 | assertThat(server.getServerUrl(), is("https://gitlab.com"));
30 | assertThat(server.getCredentialsId(), nullValue());
31 | assertThat(server.getHooksRootUrl(), is("https://myhooks/"));
32 | }
33 |
34 | @Test
35 | public void testFixEmptyAndTrimTwo() throws Exception {
36 | GitLabServer server = new GitLabServer(" https://gitlab.com ", " default ", null);
37 | server.setHooksRootUrl(" https://myhooks/ ");
38 | assertThat(server.getName(), is("default"));
39 | assertThat(server.getServerUrl(), is("https://gitlab.com"));
40 | assertThat(server.getCredentialsId(), nullValue());
41 | assertThat(server.getHooksRootUrl(), is("https://myhooks/"));
42 | }
43 |
44 | @Test
45 | public void testFixEmptyAndTrimThree() throws Exception {
46 | GitLabServer server = new GitLabServer(null, null, null);
47 | server.setHooksRootUrl(null);
48 | assertThat(server.getName(), startsWith("gitlab-"));
49 | assertThat(server.getServerUrl(), is("https://gitlab.com"));
50 | assertThat(server.getCredentialsId(), nullValue());
51 | assertThat(server.getHooksRootUrl(), nullValue());
52 | }
53 |
54 | @Test
55 | public void testFixEmptyAndTrimFour() throws Exception {
56 | GitLabServer server = new GitLabServer("https://whatever.com", "whatever", null);
57 | server.setHooksRootUrl("https://myhooks/");
58 | assertThat(server.getName(), is("whatever"));
59 | assertThat(server.getServerUrl(), is("https://whatever.com"));
60 | assertThat(server.getCredentialsId(), nullValue());
61 | assertThat(server.getHooksRootUrl(), is("https://myhooks/"));
62 | }
63 |
64 | @Test
65 | public void testFixEmptyAndTrimFive() throws Exception {
66 | GitLabServer server = new GitLabServer("", "", "");
67 | server.setHooksRootUrl("");
68 | assertThat(server.getName(), startsWith("gitlab-"));
69 | assertThat(server.getServerUrl(), is("https://gitlab.com"));
70 | assertThat(server.getCredentialsId(), is(""));
71 | assertThat(server.getHooksRootUrl(), nullValue());
72 | }
73 |
74 | @Test
75 | @Issue("SECURITY-3251")
76 | public void testGetDoCheckServerUrl() throws IOException, SAXException {
77 | try (WebClient wc = j.createWebClient()) {
78 | wc.setThrowExceptionOnFailingStatusCode(false);
79 | HtmlPage page = wc.goTo(
80 | "descriptorByName/io.jenkins.plugins.gitlabserverconfig.servers.GitLabServer/checkServerUrl?serverUrl=http://attacker.example.com");
81 | assertEquals(
82 | HttpStatus.SC_NOT_FOUND,
83 | page.getWebResponse().getStatusCode()); // Should be 405 but Stapler doesn't work that way.
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/src/test/java/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServersTest.java:
--------------------------------------------------------------------------------
1 | package io.jenkins.plugins.gitlabserverconfig.servers;
2 |
3 | import static org.hamcrest.MatcherAssert.assertThat;
4 | import static org.hamcrest.Matchers.containsString;
5 | import static org.hamcrest.Matchers.equalTo;
6 | import static org.hamcrest.Matchers.hasItem;
7 | import static org.hamcrest.Matchers.hasSize;
8 | import static org.hamcrest.Matchers.not;
9 |
10 | import com.cloudbees.plugins.credentials.Credentials;
11 | import com.cloudbees.plugins.credentials.CredentialsMatchers;
12 | import com.cloudbees.plugins.credentials.CredentialsProvider;
13 | import com.cloudbees.plugins.credentials.domains.DomainRequirement;
14 | import edu.umd.cs.findbugs.annotations.NonNull;
15 | import edu.umd.cs.findbugs.annotations.Nullable;
16 | import hudson.diagnosis.OldDataMonitor;
17 | import hudson.model.ItemGroup;
18 | import hudson.security.ACL;
19 | import java.util.List;
20 | import java.util.logging.Level;
21 | import jenkins.model.Jenkins;
22 | import org.acegisecurity.Authentication;
23 | import org.jenkinsci.plugins.plaincredentials.StringCredentials;
24 | import org.junit.Rule;
25 | import org.junit.Test;
26 | import org.jvnet.hudson.test.JenkinsRule;
27 | import org.jvnet.hudson.test.LoggerRule;
28 | import org.jvnet.hudson.test.TestExtension;
29 | import org.jvnet.hudson.test.recipes.LocalData;
30 |
31 | public class GitLabServersTest {
32 | @Rule
33 | public LoggerRule logger =
34 | new LoggerRule().record(OldDataMonitor.class, Level.FINE).capture(50);
35 |
36 | @Rule
37 | public JenkinsRule j = new JenkinsRule();
38 |
39 | @LocalData
40 | @Test
41 | public void migrationToCredentials() throws Throwable {
42 | // LocalData creating using the following:
43 | /*
44 | GitLabServer server = new GitLabServer("http://localhost", "my-server", null);
45 | server.setSecretToken(Secret.fromString("s3cr3t!"));
46 | GitLabServers.get().addServer(server);
47 | */
48 | var server = GitLabServers.get().getServers().stream()
49 | .filter(s -> s.getName().equals("my-server"))
50 | .findFirst()
51 | .orElseThrow();
52 | var credentialsId = server.getWebhookSecretCredentialsId();
53 | var credentials = CredentialsMatchers.filter(
54 | CredentialsProvider.lookupCredentialsInItemGroup(StringCredentials.class, Jenkins.get(), ACL.SYSTEM2),
55 | CredentialsMatchers.withId(credentialsId));
56 | assertThat(credentials, hasSize(1));
57 | assertThat(credentials.get(0).getSecret().getPlainText(), equalTo("s3cr3t!"));
58 | assertThat(
59 | logger.getMessages(), not(hasItem(containsString("Trouble loading " + GitLabServers.class.getName()))));
60 | }
61 |
62 | @TestExtension("migrationToCredentials")
63 | public static class CredentialsProviderThatRequiresDescriptorLookup extends CredentialsProvider {
64 | @Override
65 | public List getCredentials(
66 | @NonNull Class type,
67 | @Nullable ItemGroup itemGroup,
68 | @Nullable Authentication authentication,
69 | @NonNull List domainRequirements) {
70 | // Prior to fix, this caused the GitLabServer migration code to recurse infinitely, causing problems when
71 | // starting Jenkins.
72 | // In practice this was caused by a lookup of another descriptor type, but I am using GitLabServers for
73 | // clarity.
74 | Jenkins.get().getDescriptor(GitLabServers.class);
75 | return List.of();
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/src/test/resources/io/jenkins/plugins/gitlabserverconfig/casc/configuration-as-code.yml:
--------------------------------------------------------------------------------
1 | credentials:
2 | system:
3 | domainCredentials:
4 | - credentials:
5 | - gitlabPersonalAccessToken:
6 | scope: SYSTEM
7 | id: "i<3GitLab"
8 | token: "glpat-XfsqZvVtAx5YCph5bq3r"
9 |
10 | unclassified:
11 | gitLabServers:
12 | servers:
13 | - credentialsId: "i<3GitLab"
14 | hooksRootUrl: "https://jenkins.intranet/"
15 | manageSystemHooks: true
16 | manageWebHooks: true
17 | name: gitlab-3213
18 | serverUrl: "https://gitlab.com"
19 |
--------------------------------------------------------------------------------
/src/test/resources/io/jenkins/plugins/gitlabserverconfig/casc/expected_output.yml:
--------------------------------------------------------------------------------
1 | servers:
2 | - credentialsId: "i<3GitLab"
3 | hooksRootUrl: "https://jenkins.intranet/"
4 | manageSystemHooks: true
5 | manageWebHooks: true
6 | name: "gitlab-[0-9]{4}"
7 | serverUrl: "https://gitlab.com"
8 |
--------------------------------------------------------------------------------
/src/test/resources/io/jenkins/plugins/gitlabserverconfig/credentials/PersonalAccessTokenImplTest/CredentialsBuilder/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/test/resources/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServersTest/migrationToCredentials/io.jenkins.plugins.gitlabserverconfig.servers.GitLabServers.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | default
6 | https://gitlab.com
7 | false
8 | false
9 |
10 |
11 | false
12 |
13 |
14 | my-server
15 | http://localhost
16 | false
17 | false
18 | s3cr3t!
19 |
20 | false
21 |
22 |
23 |
--------------------------------------------------------------------------------