Java Code Examples for org.gitlab.api.models.GitlabProject#getId()

The following examples show how to use org.gitlab.api.models.GitlabProject#getId() . 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: 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 2
Source File: GitLabMapping.java    From git-as-svn with GNU General Public License v2.0 5 votes vote down vote up
@Nullable
GitLabProject updateRepository(@NotNull GitlabProject project) throws IOException {
  final Set<String> branches = getBranchesToExpose(project);
  if (branches.isEmpty()) {
    removeRepository(project.getId(), project.getPathWithNamespace());
    return null;
  }

  final String projectKey = StringHelper.normalizeDir(project.getPathWithNamespace());
  final GitLabProject oldProject = mapping.get(projectKey);

  if (oldProject != null && oldProject.getProjectId() == project.getId()) {
    final Set<String> oldBranches = oldProject.getBranches().values().stream().map(GitBranch::getShortBranchName).collect(Collectors.toSet());
    if (oldBranches.equals(branches))
      // Old project is good enough already
      return oldProject;
  }

  // TODO: do not drop entire repo here, instead only apply diff - add missing branches and remove unneeded
  removeRepository(project.getId(), project.getPathWithNamespace());

  final Path basePath = ConfigHelper.joinPath(context.getBasePath(), config.getPath());
  final String sha256 = Hashing.sha256().hashString(project.getId().toString(), Charset.defaultCharset()).toString();
  Path repoPath = basePath.resolve(HASHED_PATH).resolve(sha256.substring(0, 2)).resolve(sha256.substring(2, 4)).resolve(sha256 + ".git");
  if (!Files.exists(repoPath))
    repoPath = ConfigHelper.joinPath(basePath, project.getPathWithNamespace() + ".git");
  final LocalContext local = new LocalContext(context, project.getPathWithNamespace());
  local.add(VcsAccess.class, new GitLabAccess(local, config, project.getId()));
  final GitRepository repository = config.getTemplate().create(local, repoPath, branches);
  final GitLabProject newProject = new GitLabProject(local, repository, project.getId());
  if (mapping.compute(projectKey, (key, value) -> value != null && value.getProjectId() == project.getId() ? value : newProject) == newProject) {
    return newProject;
  }
  return null;
}