org.gitlab.api.http.Query Java Examples

The following examples show how to use org.gitlab.api.http.Query. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GitlabAPI.java    From java-gitlab-api with Apache License 2.0 6 votes vote down vote up
/**
 * Updates a Merge Request
 *
 * @param projectId       The id of the project
 * @param mergeRequestIid The internal id of the merge request to update
 * @param targetBranch    The target branch of the merge request, otherwise null to leave it untouched
 * @param assigneeId      The id of the assignee, otherwise null to leave it untouched
 * @param title           The title of the merge request, otherwise null to leave it untouched
 * @param description     The description of the merge request, otherwise null to leave it untouched
 * @param stateEvent      The state (close|reopen|merge) of the merge request, otherwise null to leave it untouched
 * @param labels          A comma separated list of labels, otherwise null to leave it untouched
 * @return the Merge Request
 * @throws IOException on gitlab api call error
 */
public GitlabMergeRequest updateMergeRequest(Serializable projectId, Integer mergeRequestIid, String targetBranch,
                                             Integer assigneeId, String title, String description, String stateEvent,
                                             String labels) throws IOException {
    Query query = new Query()
            .appendIf("target_branch", targetBranch)
            .appendIf("assignee_id", assigneeId)
            .appendIf("title", title)
            .appendIf("description", description)
            .appendIf("state_event", stateEvent)
            .appendIf("labels", labels);

    String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) +
            GitlabMergeRequest.URL + "/" + mergeRequestIid + query.toString();

    return retrieve().method(PUT).to(tailUrl, GitlabMergeRequest.class);
}
 
Example #2
Source File: GitlabAPI.java    From java-gitlab-api with Apache License 2.0 6 votes vote down vote up
public GitlabProjectHook editProjectHook(GitlabProject project, String hookId, String url,
    boolean pushEvents, boolean issuesEvents, boolean mergeRequestEvents, boolean noteEvents,
    boolean tagPushEvents, boolean sslVerification, boolean jobEvents, boolean pipelineEvents,
    boolean wikiPageEvents, String token) throws IOException {
    Query query = new Query();
    query.append("url", url);
    query.append("push_events", String.valueOf(pushEvents));
    query.append("issues_events", String.valueOf(issuesEvents));
    query.append("merge_request_events", String.valueOf(mergeRequestEvents));
    query.append("note_events", String.valueOf(noteEvents));
    query.append("tag_push_events", String.valueOf(tagPushEvents));
    query.append("enable_ssl_verification", String.valueOf(sslVerification));
    query.append("job_events", String.valueOf(jobEvents));
    query.append("pipeline_events", String.valueOf(pipelineEvents));
    query.append("wiki_page_events", String.valueOf(wikiPageEvents));
    query.append("token", token);
    String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabProjectHook.URL + "/" + hookId + query.toString();
    return retrieve().method(PUT).to(tailUrl, GitlabProjectHook.class);
}
 
Example #3
Source File: GitlabAPI.java    From java-gitlab-api with Apache License 2.0 6 votes vote down vote up
/**
 * Updates a Group
 *
 * @param group the group object
 * @param sudoUser The user to create the group on behalf of
 * @return The GitLab Group
 * @throws IOException on gitlab api call error
 */
public GitlabGroup updateGroup(GitlabGroup group, GitlabUser sudoUser) throws IOException {

    Query query = new Query()
            .appendIf("name", group.getName())
            .appendIf("path", group.getPath())
            .appendIf("description", group.getDescription())
            .appendIf("membership_lock", group.getMembershipLock())
            .appendIf("share_with_group_lock", group.getShareWithGroupLock())
            .appendIf("visibility", group.getVisibility().toString())
            .appendIf("lfs_enabled", group.isLfsEnabled())
            .appendIf("request_access_enabled", group.isRequestAccessEnabled())
            .appendIf("shared_runners_minutes_limit", group.getSharedRunnersMinutesLimit())
            .appendIf("ldap_cn", group.getLdapCn())
            .appendIf("ldap_access", group.getLdapAccess())
            .appendIf(PARAM_SUDO, sudoUser != null ? sudoUser.getId() : null);

    String tailUrl = GitlabGroup.URL + "/" + group.getId() + query.toString();

    return retrieve().method(PUT).to(tailUrl, GitlabGroup.class);
}
 
Example #4
Source File: GitlabAPI.java    From java-gitlab-api with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a Group
 *
 * @param group The gitlab Group object
 * @param sudoUser The user to create the group on behalf of
 *
 * @return The GitLab Group
 * @throws IOException on gitlab api call error
 */
public GitlabGroup createGroup(GitlabGroup group, GitlabUser sudoUser) throws IOException {

    Query query = new Query()
            .append("name", group.getName())
            .append("path", group.getPath())
            .appendIf("description", group.getDescription())
            .appendIf("membership_lock", group.getMembershipLock())
            .appendIf("share_with_group_lock", group.getShareWithGroupLock())
            .appendIf("visibility", group.getVisibility().toString())
            .appendIf("lfs_enabled", group.isLfsEnabled())
            .appendIf("request_access_enabled", group.isRequestAccessEnabled())
            .appendIf("shared_runners_minutes_limit", group.getSharedRunnersMinutesLimit())
            .appendIf("ldap_cn", group.getLdapCn())
            .appendIf("ldap_access", group.getLdapAccess())
            .appendIf(PARAM_SUDO, sudoUser != null ? sudoUser.getId() : null);

    String tailUrl = GitlabGroup.URL + query.toString();

    return dispatch().to(tailUrl, GitlabGroup.class);
}
 
Example #5
Source File: GitlabAPI.java    From java-gitlab-api with Apache License 2.0 6 votes vote down vote up
/**
 * Update recipients for email-on-push service for a projectId.
 *
 * @param projectId    The ID of the project containing the variable.
 * @param emailAddress The emailaddress of the recipent who is going to receive push notification.
 * @return
 * @throws IOException on gitlab api call error
 */
public boolean updateEmailsOnPush(Integer projectId, String emailAddress) throws IOException {
    GitlabServiceEmailOnPush emailOnPush = this.getEmailsOnPush(projectId);
    GitlabEmailonPushProperties properties = emailOnPush.getProperties();
    String appendedRecipients = properties.getRecipients();
    if (appendedRecipients != "") {
        if (appendedRecipients.contains(emailAddress))
            return true;
        appendedRecipients = appendedRecipients + " " + emailAddress;
    } else
        appendedRecipients = emailAddress;

    Query query = new Query()
            .appendIf("active", true)
            .appendIf("recipients", appendedRecipients);

    String tailUrl = GitlabProject.URL + "/" + projectId + GitlabServiceEmailOnPush.URL + query.toString();
    return retrieve().method(PUT).to(tailUrl, Boolean.class);
}
 
Example #6
Source File: GitlabAPI.java    From java-gitlab-api with Apache License 2.0 6 votes vote down vote up
/**
 * Set JIRA service for a project.
 * https://docs.gitlab.com/ce/api/services.html#create-edit-jira-service
 *
 * @param projectId    The ID of the project containing the variable.
 * @param jiraPropties
 * @return
 * @throws IOException on gitlab api call error
 */
public boolean createOrEditJiraService(Integer projectId, GitlabJiraProperties jiraPropties) throws IOException {

    Query query = new Query()
            .appendIf("url", jiraPropties.getUrl())
            .appendIf("project_key", jiraPropties.getProjectKey());

    if (!jiraPropties.getUsername().isEmpty()) {
        query.appendIf("username", jiraPropties.getUsername());
    }

    if (!jiraPropties.getPassword().isEmpty()) {
        query.appendIf("password", jiraPropties.getPassword());
    }

    if (jiraPropties.getIssueTransitionId() != null) {
        query.appendIf("jira_issue_transition_id", jiraPropties.getIssueTransitionId());
    }


    String tailUrl = GitlabProject.URL + "/" + projectId + GitlabServiceJira.URL + query.toString();
    return retrieve().method(PUT).to(tailUrl, Boolean.class);

}
 
Example #7
Source File: GitlabAPI.java    From java-gitlab-api with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a Project
 *
 * @param name                 The name of the project
 * @param namespaceId          The Namespace for the new project, otherwise null indicates to use the GitLab default (user)
 * @param description          A description for the project, null otherwise
 * @param issuesEnabled        Whether Issues should be enabled, otherwise null indicates to use GitLab default
 * @param wallEnabled          Whether The Wall should be enabled, otherwise null indicates to use GitLab default
 * @param mergeRequestsEnabled Whether Merge Requests should be enabled, otherwise null indicates to use GitLab default
 * @param wikiEnabled          Whether a Wiki should be enabled, otherwise null indicates to use GitLab default
 * @param snippetsEnabled      Whether Snippets should be enabled, otherwise null indicates to use GitLab default
 * @param visibility           The visibility level of the project, otherwise null indicates to use GitLab default
 * @param importUrl            The Import URL for the project, otherwise null
 * @return the Gitlab Project
 * @throws IOException on gitlab api call error
 */
@Deprecated
public GitlabProject createProject(String name, Integer namespaceId, String description, Boolean issuesEnabled, Boolean wallEnabled, Boolean mergeRequestsEnabled, Boolean wikiEnabled, Boolean snippetsEnabled, Boolean publik, String visibility, String importUrl) throws IOException {
    Query query = new Query()
            .append("name", name)
            .appendIf("namespace_id", namespaceId)
            .appendIf("description", description)
            .appendIf("issues_enabled", issuesEnabled)
            .appendIf("wall_enabled", wallEnabled)
            .appendIf("merge_requests_enabled", mergeRequestsEnabled)
            .appendIf("wiki_enabled", wikiEnabled)
            .appendIf("snippets_enabled", snippetsEnabled)
            .appendIf("visibility", visibility)
            .appendIf("import_url", importUrl);

    String tailUrl = GitlabProject.URL + query.toString();

    return dispatch().to(tailUrl, GitlabProject.class);
}
 
Example #8
Source File: GitlabAPI.java    From java-gitlab-api with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a Project for a specific User
 *
 * @param userId               The id of the user to create the project for
 * @param name                 The name of the project
 * @param description          A description for the project, null otherwise
 * @param defaultBranch        The default branch for the project, otherwise null indicates to use GitLab default (master)
 * @param issuesEnabled        Whether Issues should be enabled, otherwise null indicates to use GitLab default
 * @param wallEnabled          Whether The Wall should be enabled, otherwise null indicates to use GitLab default
 * @param mergeRequestsEnabled Whether Merge Requests should be enabled, otherwise null indicates to use GitLab default
 * @param wikiEnabled          Whether a Wiki should be enabled, otherwise null indicates to use GitLab default
 * @param snippetsEnabled      Whether Snippets should be enabled, otherwise null indicates to use GitLab default
 * @param visibility           The visibility level of the project, otherwise null indicates to use GitLab default
 * @param importUrl            The Import URL for the project, otherwise null
 * @return The GitLab Project
 * @throws IOException on gitlab api call error
 */
@Deprecated
public GitlabProject createUserProject(Integer userId, String name, String description, String defaultBranch, Boolean issuesEnabled, Boolean wallEnabled, Boolean mergeRequestsEnabled, Boolean wikiEnabled, Boolean snippetsEnabled, String visibility, String importUrl) throws IOException {
    Query query = new Query()
            .append("name", name)
            .appendIf("description", description)
            .appendIf("default_branch", defaultBranch)
            .appendIf("issues_enabled", issuesEnabled)
            .appendIf("wall_enabled", wallEnabled)
            .appendIf("merge_requests_enabled", mergeRequestsEnabled)
            .appendIf("wiki_enabled", wikiEnabled)
            .appendIf("snippets_enabled", snippetsEnabled)
            .appendIf("visibility", visibility)
            .appendIf("import_url", importUrl);

    String tailUrl = GitlabProject.URL + "/user/" + userId + query.toString();

    return dispatch().to(tailUrl, GitlabProject.class);
}
 
Example #9
Source File: CreateUserRequest.java    From java-gitlab-api with Apache License 2.0 6 votes vote down vote up
/**
 * Generates a query based on this request's properties.
 * @return {@link Query}
 * @throws UnsupportedEncodingException
 */
public Query toQuery() throws UnsupportedEncodingException{
  return new Query()
  .appendIf("email", email)
  .appendIf("password", password)
  .appendIf("reset_password", resetPassword)
  .appendIf("username", username)
  .appendIf("name", name)
  .appendIf("skype", skype)
  .appendIf("linkedin", linkedin)
  .appendIf("twitter", twitter)
  .appendIf("website_url", websiteUrl)
  .appendIf("organization", organization)
  .appendIf("projects_limit", projectsLimit)
  .appendIf("extern_uid", externUid)
  .appendIf("provider", provider)
  .appendIf("bio", bio)
  .appendIf("location", location)
  .appendIf("admin", admin)
  .appendIf("can_create_group", canCreateGroup)
  .appendIf("skip_confirmation", skipConfirmation)
  .appendIf("external", external)
  .appendIf("avatar", avatar);
  
}
 
Example #10
Source File: GitlabAPI.java    From java-gitlab-api with Apache License 2.0 6 votes vote down vote up
public List<GitlabCommit> getCommits(Serializable projectId, Pagination pagination,
                                     String branchOrTag, String path) throws IOException {
    final Query query = new Query();
    if (branchOrTag != null) {
        query.append("ref_name", branchOrTag);
    }
    if (path != null) {
        query.append("path", path);
    }
    if (pagination != null) {
        query.mergeWith(pagination.asQuery());
    }

    String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) +
            "/repository" + GitlabCommit.URL + query;
    final GitlabCommit[] commits = retrieve().to(tailUrl, GitlabCommit[].class);
    return Arrays.asList(commits);
}
 
Example #11
Source File: GitlabAPI.java    From java-gitlab-api with Apache License 2.0 6 votes vote down vote up
/**
 * Create a new discussion with position type text on the given merge request.
 * <a href="https://docs.gitlab.com/ce/api/discussions.html#create-new-merge-request-discussion">https://docs.gitlab.com/ce/api/discussions.html#create-new-merge-request-discussion</a>
 *
 * @param mergeRequest      The merge request where the discussion is created.
 * @param body              The content of a discussion.
 * @param position          The position when creating a diff note. (hash)
 * @param positionBaseSha   The base commit SHA in the source branch.
 * @param positionStartSha  The SHA referencing the commit in the target branch.
 * @param positionHeadSha   The SHA referencing the HEAD of this merge request.
 * @param positionNewPath   The file path after the change.
 * @param positionNewLine   The Line number after change
 * @param positionOldPath   The file path before the change.
 * @param positionOldLine   The Line number before change.
 *
 * @return The created discussion object.
 * @throws IOException on a GitLab api call error
 */
public GitlabDiscussion createTextDiscussion(GitlabMergeRequest mergeRequest,
        String body, String position, String positionBaseSha, String positionStartSha,
        String positionHeadSha, String positionNewPath, Integer positionNewLine,
        String positionOldPath, Integer positionOldLine) throws IOException {
    checkRequiredCreateDiscussionArguments(body, positionBaseSha, positionStartSha, positionHeadSha);
    Query query = new Query()
            .append("body", body)
            .appendIf("position", position)
            .append("position[base_sha]", positionBaseSha)
            .append("position[start_sha]", positionStartSha)
            .append("position[head_sha]", positionHeadSha)
            .append("position[position_type]", "text")
            .appendIf("position[new_path]", positionNewPath)
            .appendIf("position[new_line]", positionNewLine)
            .appendIf("position[old_path]", positionOldPath)
            .appendIf("position[old_line]", positionOldLine);

    String tailUrl = GitlabProject.URL + "/" + mergeRequest.getProjectId() +
            GitlabMergeRequest.URL + "/" + mergeRequest.getIid() +
            GitlabDiscussion.URL + query.toString();

    return dispatch().to(tailUrl, GitlabDiscussion.class);
}
 
Example #12
Source File: GitlabAPI.java    From java-gitlab-api with Apache License 2.0 5 votes vote down vote up
/**
 * Post comment to commit
 *
 * @param projectId (required) - The ID of a project
 * @param sha       (required) - The name of a repository branch or tag or if not given the default branch
 * @param note      (required) - Text of comment
 * @param path      (optional) - The file path
 * @param line      (optional) - The line number
 * @param line_type (optional) - The line type (new or old)
 * @return A CommitComment
 * @throws IOException on gitlab api call error
 * @see <a href="http://doc.gitlab.com/ce/api/commits.html#post-comment-to-commit">http://doc.gitlab.com/ce/api/commits.html#post-comment-to-commit</a>
 */
public CommitComment createCommitComment(Serializable projectId, String sha, String note,
                                         String path, String line, String line_type) throws IOException {

    Query query = new Query()
            .append("id", projectId.toString())
            .appendIf("sha", sha)
            .appendIf("note", note)
            .appendIf("path", path)
            .appendIf("line", line)
            .appendIf("line_type", line_type);
    String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + "/repository/commits/" + sha + CommitComment.URL + query.toString();

    return dispatch().to(tailUrl, CommitComment.class);
}
 
Example #13
Source File: PaginationTest.java    From java-gitlab-api with Apache License 2.0 5 votes vote down vote up
@Test
public void complexPagination() throws UnsupportedEncodingException {
    Pagination pagination = new Pagination();
    pagination.setPage(1);
    pagination.setPerPage(50);

    final Query expectedQuery = new Query()
            .append(Pagination.PARAM_PAGE, "1")
            .append(Pagination.PARAM_PER_PAGE, "50");

    assertEquals(expectedQuery.toString(), pagination.toString());
    assertEquals(expectedQuery.toString(), pagination.asQuery().toString());
}
 
Example #14
Source File: GitlabAPI.java    From java-gitlab-api with Apache License 2.0 5 votes vote down vote up
private GitlabSSHKey createDeployKey(Integer targetProjectId, String title, String key, boolean canPush) throws IOException {
    Query query = new Query()
            .append("title", title)
            .append("key", key)
            .append("can_push", Boolean.toString(canPush));

    String tailUrl = GitlabProject.URL + "/" + targetProjectId + GitlabSSHKey.DEPLOY_KEYS_URL + query.toString();

    return dispatch().to(tailUrl, GitlabSSHKey.class);
}
 
Example #15
Source File: GitlabAPI.java    From java-gitlab-api with Apache License 2.0 5 votes vote down vote up
/**
 * Create an award for a merge request
 *
 * @param mergeRequest
 * @param awardName
 * @throws IOException on gitlab api call error
 */
public GitlabAward createAward(GitlabMergeRequest mergeRequest, String awardName) throws IOException {
    Query query = new Query().append("name", awardName);
    String tailUrl = GitlabProject.URL + "/" + mergeRequest.getProjectId() + GitlabMergeRequest.URL + "/"
            + mergeRequest.getIid() + GitlabAward.URL + query.toString();

    return dispatch().to(tailUrl, GitlabAward.class);
}
 
Example #16
Source File: GitlabAPI.java    From java-gitlab-api with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a list of runners with perPage elements on the page number specified.
 *
 * @param scope      Can be null. Defines type of Runner to retrieve.
 * @param pagination Can be null. Pagination to query by.
 * @return List of GitlabRunners
 * @throws IOException on Gitlab API call error
 */
public List<GitlabRunner> getRunnersWithPagination(GitlabRunner.RunnerScope scope, Pagination pagination) throws IOException {
    StringBuilder tailUrl = new StringBuilder(GitlabRunner.URL).append("/all");
    Query query = new Query()
            .appendIf("scope", scope.getScope());

    if (pagination != null) {
        query.mergeWith(pagination.asQuery());
    }

    tailUrl.append(query.toString());
    return Arrays.asList(retrieve().method(GET).to(tailUrl.toString(), GitlabRunner[].class));
}
 
Example #17
Source File: GitlabAPI.java    From java-gitlab-api with Apache License 2.0 5 votes vote down vote up
/**
 * Get events for a project.
 *
 * @param action If not null, include only events of a particular action type
 * @param targetType If not null, include only events of a particular target type
 * @param before If not null, include only events created before a particular date.
 * @param after If not null, include only events created before a
 * particular date.
 * @param sort If null, uses the server's default, which is "desc"
 */
public List<GitlabEvent> getProjectEvents(Serializable projectId,
                                          GitlabEvent.ActionType action,
                                          GitlabEvent.TargetType targetType,
                                          GitlabDate before,
                                          GitlabDate after,
                                          SortOrder sort,
                                          Pagination pagination)
    throws IOException {

    final Query query = new Query();
    query.appendIf("action", action);
    query.appendIf("target_type", targetType);
    query.appendIf("before", before);
    query.appendIf("after", after);
    query.appendIf("sort", sort);

    if (pagination != null) {
        query.mergeWith(pagination.asQuery());
    }

    StringBuilder tailUrl = new StringBuilder(GitlabProject.URL)
        .append("/")
        .append(sanitizeProjectId(projectId))
        .append(GitlabEvent.URL)
        .append(query.toString());

    return Arrays.asList(retrieve().method(GET).to(tailUrl.toString(), GitlabEvent[].class));
}
 
Example #18
Source File: PaginationTest.java    From java-gitlab-api with Apache License 2.0 5 votes vote down vote up
@Test
public void emptyPagination() {
    Pagination pagination = new Pagination();

    final Query expectedQuery = new Query();
    assertEquals(expectedQuery.toString(), pagination.toString());
    assertEquals(expectedQuery.toString(), pagination.asQuery().toString());
}
 
Example #19
Source File: PaginationTest.java    From java-gitlab-api with Apache License 2.0 5 votes vote down vote up
@Test
public void pageOnlyPagination() throws UnsupportedEncodingException {
    Pagination pagination = new Pagination();
    pagination.setPage(1);

    final Query expectedQuery = new Query()
            .append(Pagination.PARAM_PAGE, "1");

    assertEquals(expectedQuery.toString(), pagination.toString());
    assertEquals(expectedQuery.toString(), pagination.asQuery().toString());
}
 
Example #20
Source File: PaginationTest.java    From java-gitlab-api with Apache License 2.0 5 votes vote down vote up
@Test
public void perPageOnlyPagination() throws UnsupportedEncodingException {
    Pagination pagination = new Pagination();
    pagination.setPerPage(50);

    final Query expectedQuery = new Query()
            .append(Pagination.PARAM_PER_PAGE, "50");

    assertEquals(expectedQuery.toString(), pagination.toString());
    assertEquals(expectedQuery.toString(), pagination.asQuery().toString());
}
 
Example #21
Source File: GitlabRepositoryApiImpl.java    From bistoury with GNU General Public License v3.0 5 votes vote down vote up
private ApiResult doFile(final String projectId, final String ref, final String filepath) throws IOException {
    try {
        final GitlabAPI api = createGitlabApi();
        final GitlabProject project = api.getProject(projectId);
        final Query query = new Query().append("file_path", filepath).append("ref", ref);
        final String url = "/projects/" + project.getId() + "/repository/files" + query.toString();
        return ResultHelper.success(api.retrieve().to(url, GitlabFile.class));
    } catch (GitlabAPIException e) {
        Metrics.counter("connect_gitlab_error").inc();
        return ResultHelper.fail(-1, "连接gitlab服务器失败,请核private token", e);
    } catch (FileNotFoundException fnfe) {
        return ResultHelper.fail(-1, "文件不存在,请核对仓库地址", fnfe);
    }
}
 
Example #22
Source File: GitlabAPI.java    From java-gitlab-api with Apache License 2.0 5 votes vote down vote up
/**
 * Share a project with a group.
 *
 * @param accessLevel The permissions level to grant the group.
 * @param group       The group to share with.
 * @param project     The project to be shared.
 * @param expiration  Share expiration date in ISO 8601 format: 2016-09-26 or {@code null}.
 * @throws IOException on gitlab api call error
 */
public void shareProjectWithGroup(GitlabAccessLevel accessLevel, String expiration, GitlabGroup group, GitlabProject project) throws IOException {
    Query query = new Query()
            .append("group_id", group.getId().toString())
            .append("group_access", String.valueOf(accessLevel.accessValue))
            .appendIf("expires_at", expiration);

    String tailUrl = GitlabProject.URL + "/" + project.getId() + "/share" + query.toString();
    dispatch().to(tailUrl, Void.class);
}
 
Example #23
Source File: GitlabAPI.java    From java-gitlab-api with Apache License 2.0 5 votes vote down vote up
public GitlabCommitComparison compareCommits(Serializable projectId, String commitHash1, String commitHash2, Pagination pagination) throws IOException {
    String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabCommitComparison.URL;
    Query query = new Query()
            .append("from", commitHash1)
            .append("to", commitHash2);
    query.mergeWith(pagination.asQuery());
    return retrieve().to(tailUrl + query, GitlabCommitComparison.class);
}
 
Example #24
Source File: GitlabAPI.java    From java-gitlab-api with Apache License 2.0 5 votes vote down vote up
public GitlabProjectHook addProjectHook(GitlabProject project, String url) throws IOException {
    Query query = new Query()
            .append("url", url);

    String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabProjectHook.URL + query.toString();
    return dispatch().to(tailUrl, GitlabProjectHook.class);
}
 
Example #25
Source File: GitlabAPI.java    From java-gitlab-api with Apache License 2.0 5 votes vote down vote up
public void protectBranchWithDeveloperOptions(GitlabProject project, String branchName, boolean developers_can_push, boolean developers_can_merge) throws IOException {
    String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabBranch.URL + '/' + sanitizePath(branchName) + "/protect";
    final Query query = new Query()
            .append("developers_can_push", Boolean.toString(developers_can_push))
            .append("developers_can_merge", Boolean.toString(developers_can_merge));
    retrieve().method(PUT).to(tailUrl + query.toString(), Void.class);
}
 
Example #26
Source File: GitlabAPI.java    From java-gitlab-api with Apache License 2.0 5 votes vote down vote up
/**
 * Update a Merge Request Note
 *
 * @param mergeRequest The merge request
 * @param noteId       The id of the note
 * @param body         The content of the note
 * @return the Gitlab Note
 * @throws IOException on gitlab api call error
 */
public GitlabNote updateNote(GitlabMergeRequest mergeRequest, Integer noteId, String body) throws IOException {
    Query query = new Query()
            .appendIf("body", body);

    String tailUrl = GitlabProject.URL + "/" + mergeRequest.getProjectId() +
            GitlabMergeRequest.URL + "/" + mergeRequest.getIid() + GitlabNote.URL + "/" + noteId + query.toString();

    return retrieve().method(PUT).to(tailUrl, GitlabNote.class);
}
 
Example #27
Source File: GitlabAPI.java    From java-gitlab-api with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new discussion with position type image on the given merge request.
 * <a href="https://docs.gitlab.com/ce/api/discussions.html#create-new-merge-request-discussion">https://docs.gitlab.com/ce/api/discussions.html#create-new-merge-request-discussion</a>
 *
 * @param mergeRequest      The merge request where the discussion is created.
 * @param body              The content of a discussion.
 * @param position          The position when creating a diff note. (hash)
 * @param positionBaseSha   The base commit SHA in the source branch.
 * @param positionStartSha  The SHA referencing the commit in the target branch.
 * @param positionHeadSha   The SHA referencing the HEAD of this merge request.
 * @param positionNewPath   The file path after the change.
 * @param positionOldPath   The file path before the change.
 * @param positionWidth     The width of the image.
 * @param positionHeight    The height of the image.
 * @param positionX         The X coordinate.
 * @param positionY         The Y coordinate.
 *
 * @return The created discussion object.
 * @throws IOException on a GitLab api call error
 */
public GitlabDiscussion createImageDiscussion(
        GitlabMergeRequest mergeRequest, String body, String position,
        String positionBaseSha, String positionStartSha,
        String positionHeadSha, String positionNewPath, String positionOldPath,
        Integer positionWidth, Integer positionHeight, Integer positionX,
        Integer positionY
    ) throws IOException {
    checkRequiredCreateDiscussionArguments(body, positionBaseSha, positionStartSha, positionHeadSha);
    Query query = new Query()
            .append("body", body)
            .appendIf("position", position)
            .append("position[base_sha]", positionBaseSha)
            .append("position[start_sha]", positionStartSha)
            .append("position[head_sha]", positionHeadSha)
            .append("position[position_type]", "image")
            .appendIf("position[new_path]", positionNewPath)
            .appendIf("position[old_path]", positionOldPath)
            .appendIf("position[width]", positionWidth)
            .appendIf("position[height]", positionHeight)
            .appendIf("position[x]", positionX)
            .appendIf("position[y]", positionY);

    String tailUrl = GitlabProject.URL + "/" + mergeRequest.getProjectId() +
            GitlabMergeRequest.URL + "/" + mergeRequest.getIid() +
            GitlabDiscussion.URL + query.toString();

    return dispatch().to(tailUrl, GitlabDiscussion.class);
}
 
Example #28
Source File: GitlabAPI.java    From java-gitlab-api with Apache License 2.0 5 votes vote down vote up
public GitlabRepositoryFile getRepositoryFile(GitlabProject project, String path, String ref) throws IOException {
    Query query = new Query()
            .append("ref", ref);

    String tailUrl = GitlabProject.URL + "/" + project.getId() + "/repository/files/" + sanitizePath(path) + query.toString();
    return retrieve().to(tailUrl, GitlabRepositoryFile.class);
}
 
Example #29
Source File: GitlabAPI.java    From java-gitlab-api with Apache License 2.0 5 votes vote down vote up
/**
 * Get an archive of the repository
 *
 * @param project The Project
 * @param path    The path inside the repository. Used to get content of subdirectories (optional)
 * @param ref     The name of a repository branch or tag or if not given the default branch (optional)
 * @throws IOException on gitlab api call error
 */
public List<GitlabRepositoryTree> getRepositoryTree(GitlabProject project, String path, String ref, boolean recursive) throws IOException {
    Query query = new Pagination().withPerPage(Pagination.MAX_ITEMS_PER_PAGE).asQuery()
            .appendIf("path", path)
            .appendIf("ref", ref)
            .appendIf("recursive", recursive);

    String tailUrl = GitlabProject.URL + "/" + project.getId() + "/repository" + GitlabRepositoryTree.URL + query.toString();
    return retrieve().getAll(tailUrl, GitlabRepositoryTree[].class);
}
 
Example #30
Source File: GitlabAPI.java    From java-gitlab-api with Apache License 2.0 5 votes vote down vote up
public List<GitlabCommit> getAllCommits(Serializable projectId, Pagination pagination,
                                        String branchOrTag) throws IOException {
    final Query query = new Query();
    if (branchOrTag != null) {
        query.append("ref_name", branchOrTag);
    }

    if (pagination != null) {
        query.mergeWith(pagination.asQuery());
    }

    String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) +
            "/repository" + GitlabCommit.URL + query;
    return retrieve().getAll(tailUrl, GitlabCommit[].class);
}