Java Code Examples for org.gitlab.api.http.Query#toString()

The following examples show how to use org.gitlab.api.http.Query#toString() . 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
/**
 * 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 2
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 3
Source File: GitLabIntegrationTest.java    From git-as-svn with GNU General Public License v2.0 5 votes vote down vote up
@NotNull
private GitlabProject createGitlabProject(@NotNull GitlabAPI rootAPI, @NotNull GitlabGroup group, @NotNull String name, @NotNull GitlabVisibility visibility, @NotNull Set<String> tags) throws IOException {
  // java-gitlab-api doesn't handle tag_list, so we have to do this manually
  final Query query = new Query()
      .append("name", name)
      .appendIf("namespace_id", group.getId())
      .appendIf("visibility", visibility.toString())
      .appendIf("tag_list", String.join(",", tags));

  final String tailUrl = GitlabProject.URL + query.toString();
  return rootAPI.dispatch().to(tailUrl, GitlabProject.class);
}
 
Example 4
Source File: GitlabAPI.java    From java-gitlab-api with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new User
 *
 * @param email                User email
 * @param password             Password
 * @param username             User name
 * @param fullName             Full name
 * @param skypeId              Skype Id
 * @param linkedIn             LinkedIn
 * @param twitter              Twitter
 * @param website_url          Website URL
 * @param projects_limit       Projects limit
 * @param extern_uid           External User ID
 * @param extern_provider_name External Provider Name
 * @param bio                  Bio
 * @param isAdmin              Is Admin
 * @param can_create_group     Can Create Group
 * @param skip_confirmation    Skip Confirmation
 * @param external             External
 * @return                     A GitlabUser
 * @throws IOException on gitlab api call error
 * @see <a href="http://doc.gitlab.com/ce/api/users.html">http://doc.gitlab.com/ce/api/users.html</a>
 */
public GitlabUser createUser(String email, String password, String username,
                             String fullName, String skypeId, String linkedIn,
                             String twitter, String website_url, Integer projects_limit,
                             String extern_uid, String extern_provider_name,
                             String bio, Boolean isAdmin, Boolean can_create_group,
                             Boolean skip_confirmation, Boolean external) throws IOException {

    Query query = new Query()
            .append("email", email)
            .appendIf("skip_confirmation", skip_confirmation)
            .appendIf("password", password)
            .appendIf("username", username)
            .appendIf("name", fullName)
            .appendIf("skype", skypeId)
            .appendIf("linkedin", linkedIn)
            .appendIf("twitter", twitter)
            .appendIf("website_url", website_url)
            .appendIf("projects_limit", projects_limit)
            .appendIf("extern_uid", extern_uid)
            .appendIf("provider", extern_provider_name)
            .appendIf("bio", bio)
            .appendIf("admin", isAdmin)
            .appendIf("can_create_group", can_create_group)
            .appendIf("external", external);

    String tailUrl = GitlabUser.USERS_URL + query.toString();

    return dispatch().to(tailUrl, GitlabUser.class);
}
 
Example 5
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 6
Source File: GitlabAPI.java    From java-gitlab-api with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new ssh key for the user
 *
 * @param targetUserId The id of the Gitlab user
 * @param title        The title of the ssh key
 * @param key          The public key
 * @return The new GitlabSSHKey
 * @throws IOException on gitlab api call error
 */
public GitlabSSHKey createSSHKey(Integer targetUserId, String title, String key) throws IOException {

    Query query = new Query()
            .append("title", title)
            .append("key", key);

    String tailUrl = GitlabUser.USERS_URL + "/" + targetUserId + GitlabSSHKey.KEYS_URL + query.toString();

    return dispatch().to(tailUrl, GitlabSSHKey.class);
}
 
Example 7
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 8
Source File: GitlabAPI.java    From java-gitlab-api with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a Group
 *
 * @param name       The name of the group
 * @param path       The path for the group
 * @param ldapCn     LDAP Group Name to sync with, null otherwise
 * @param ldapAccess Access level for LDAP group members, null otherwise
 * @param sudoUser   The user to create the group on behalf of
 * @param parentId   The id of a parent group; the new group will be its subgroup
 * @return The GitLab Group
 * @throws IOException on gitlab api call error
 */
public GitlabGroup createGroup(String name, String path, String ldapCn, GitlabAccessLevel ldapAccess, GitlabUser sudoUser, Integer parentId) throws IOException {

    Query query = new Query()
            .append("name", name)
            .append("path", path)
            .appendIf("ldap_cn", ldapCn)
            .appendIf("ldap_access", ldapAccess)
            .appendIf(PARAM_SUDO, sudoUser != null ? sudoUser.getId() : null)
            .appendIf("parent_id", parentId);

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

    return dispatch().to(tailUrl, GitlabGroup.class);
}
 
Example 9
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 10
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 11
Source File: GitlabAPI.java    From java-gitlab-api with Apache License 2.0 5 votes vote down vote up
/**
   * Creates a Project
   *
   * @param project The project to create
   * @return The GitLab Project
   * @throws IOException on gitlab api call error
   */
  public GitlabProject createProject(GitlabProject project) throws IOException {
      Query query = new Query()
              .appendIf("name", project.getName())
              .appendIf("path", project.getPath())
              .appendIf("default_branch", project.getDefaultBranch())
              .appendIf("description", project.getDescription())
              .appendIf("issues_enabled", project.isIssuesEnabled())
              .appendIf("merge_requests_enabled", project.isMergeRequestsEnabled())
              .appendIf("jobs_enabled", project.isJobsEnabled())
              .appendIf("wiki_enabled", project.isWikiEnabled())
              .appendIf("snippets_enabled", project.isSnippetsEnabled())

              .appendIf("container_registry_enabled", project.isContainerRegistryEnabled())
              .appendIf("shared_runners_enabled", project.isSharedRunnersEnabled())

              .appendIf("visibility", project.getVisibility())
              .appendIf("public_jobs", project.hasPublicJobs())
              .appendIf("import_url", project.getImportUrl())

              .appendIf("only_allow_merge_if_pipeline_succeeds", project.getOnlyAllowMergeIfPipelineSucceeds())
              .appendIf("only_allow_merge_if_all_discussions_are_resolved", project.getOnlyAllowMergeIfAllDiscussionsAreResolved())
              .appendIf("lfs_enabled", project.isLfsEnabled())
              .appendIf("request_access_enabled", project.isRequestAccessEnabled())
              .appendIf("repository_storage", project.getRepositoryStorage())
              .appendIf("approvals_before_merge", project.getApprovalsBeforeMerge())
              .appendIf("printing_merge_request_link_enabled", project.isPrintingMergeRequestLinkEnabled())
.appendIf("initialize_with_readme",project.isInitializeWithReadme());

      GitlabNamespace namespace = project.getNamespace();
      if (namespace != null) {
          query.appendIf("namespace_id", namespace.getId());
      }


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

      return dispatch().to(tailUrl, GitlabProject.class);
  }
 
Example 12
Source File: GitlabAPI.java    From java-gitlab-api with Apache License 2.0 5 votes vote down vote up
/**
 * Get a list of projects owned by the authenticated user.
 *
 * @return A list of gitlab projects
 * @throws IOException on gitlab api call error
 */
public List<GitlabProject> getOwnedProjects() throws IOException {
    Query query = new Query().append("owned", "true");
    query.mergeWith(new Pagination().withPerPage(Pagination.MAX_ITEMS_PER_PAGE).asQuery());
    String tailUrl = GitlabProject.URL + query.toString();
    return retrieve().getAll(tailUrl, GitlabProject[].class);
}
 
Example 13
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 14
Source File: GitlabAPI.java    From java-gitlab-api with Apache License 2.0 5 votes vote down vote up
/**
 * Get a list of projects starred by the authenticated user.
 *
 * @return A list of gitlab projects
 * @throws IOException on gitlab api call error
 */
public List<GitlabProject> getStarredProjects() throws IOException {
    Query query = new Query().append("starred", "true");
    query.mergeWith(new Pagination().withPerPage(Pagination.MAX_ITEMS_PER_PAGE).asQuery());
    String tailUrl = GitlabProject.URL + query.toString();
    return retrieve().getAll(tailUrl, GitlabProject[].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 an issue
 *
 * @param issue
 * @param awardName
 * @throws IOException on gitlab api call error
 */
public GitlabAward createAward(GitlabIssue issue, String awardName) throws IOException {
    Query query = new Query().append("name", awardName);
    String tailUrl = GitlabProject.URL + "/" + issue.getProjectId() + GitlabIssue.URL + "/" + issue.getId()
            + 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 3 votes vote down vote up
/**
 * Add a project member.
 *
 * @param projectId   the project id
 * @param userId      the user id
 * @param accessLevel the GitlabAccessLevel
 * @return the GitlabProjectMember
 * @throws IOException on gitlab api call error
 */
public GitlabProjectMember addProjectMember(Integer projectId, Integer userId, GitlabAccessLevel accessLevel) throws IOException {
    Query query = new Query()
            .appendIf("id", projectId)
            .appendIf("user_id", userId)
            .appendIf("access_level", accessLevel);
    String tailUrl = GitlabProject.URL + "/" + projectId + GitlabProjectMember.URL + query.toString();
    return dispatch().to(tailUrl, GitlabProjectMember.class);
}
 
Example 17
Source File: GitlabAPI.java    From java-gitlab-api with Apache License 2.0 3 votes vote down vote up
/**
 * Create an award for an issue note
 *
 * @param issue
 * @param noteId
 * @param awardName
 * @throws IOException on gitlab api call error
 */
public GitlabAward createAward(GitlabIssue issue, Integer noteId, String awardName) throws IOException {
    Query query = new Query().append("name", awardName);
    String tailUrl = GitlabProject.URL + "/" + issue.getProjectId() + GitlabIssue.URL + "/" + issue.getId()
            + GitlabNote.URL + noteId + GitlabAward.URL + query.toString();

    return dispatch().to(tailUrl, GitlabAward.class);
}
 
Example 18
Source File: GitlabAPI.java    From java-gitlab-api with Apache License 2.0 3 votes vote down vote up
/**
 * Add a group member.
 *
 * @param groupId     the group id
 * @param userId      the user id
 * @param accessLevel the GitlabAccessLevel
 * @return the GitlabGroupMember
 * @throws IOException on gitlab api call error
 */
public GitlabGroupMember addGroupMember(Integer groupId, Integer userId, GitlabAccessLevel accessLevel) throws IOException {
    Query query = new Query()
            .appendIf("id", groupId)
            .appendIf("user_id", userId)
            .appendIf("access_level", accessLevel);
    String tailUrl = GitlabGroup.URL + "/" + groupId + GitlabProjectMember.URL + query.toString();
    return dispatch().to(tailUrl, GitlabGroupMember.class);
}
 
Example 19
Source File: GitlabAPI.java    From java-gitlab-api with Apache License 2.0 3 votes vote down vote up
/**
 * Updates a project member.
 *
 * @param projectId   the project id
 * @param userId      the user id
 * @param accessLevel the updated access level for the specified user
 * @param expiresAt   the date at which the user's membership expires at in the form YEAR-MONTH-DAY
 * @return GitLabProjectMember with updated access level on success
 * @throws IOException on Gitlab API call error
 */
public GitlabProjectMember updateProjectMember(Integer projectId, Integer userId, GitlabAccessLevel accessLevel, String expiresAt) throws IOException {
    Query query = new Query()
            .appendIf("access_level", accessLevel)
            .appendIf("expires_at", expiresAt);
    String tailUrl = GitlabProject.URL + "/" + projectId + GitlabProjectMember.URL + "/" + userId + query.toString();
    return retrieve().method(PUT).to(tailUrl, GitlabProjectMember.class);
}
 
Example 20
Source File: GitlabAPI.java    From java-gitlab-api with Apache License 2.0 3 votes vote down vote up
/**
 * Get raw file content
 *
 * @param projectId The Project
 * @param sha       The commit or branch name
 * @param filepath  The path of the file
 * @throws IOException on gitlab api call error
 */
public byte[] getRawFileContent(Serializable projectId, String sha, String filepath) throws IOException {
    Query query = new Query()
            .append("ref", sha);

    String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + "/repository/files/" + sanitizePath(filepath) + "/raw" + query.toString();
    return retrieve().to(tailUrl, byte[].class);
}