本文整理汇总了Java中org.gitlab.api.models.GitlabProject类的典型用法代码示例。如果您正苦于以下问题:Java GitlabProject类的具体用法?Java GitlabProject怎么用?Java GitlabProject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GitlabProject类属于org.gitlab.api.models包,在下文中一共展示了GitlabProject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isMatch
import org.gitlab.api.models.GitlabProject; //导入依赖的package包/类
private boolean isMatch(@Nonnull GitLabSCMNavigator navigator) {
if (!navigator.getListenToWebHooks() || !navigator.getHookListener().id().equals(hookId)) {
return false;
}
switch (getType()) {
case CREATED:
case UPDATED:
GitlabProject project = EventHelper.getMatchingProject(navigator, getPayload());
if (project == null) {
return false;
}
sourceName = project.getPathWithNamespace();
return true;
case REMOVED:
return true;
default:
return false;
}
}
示例2: getProjectsOfUser
import org.gitlab.api.models.GitlabProject; //导入依赖的package包/类
/**
* If the Gitlab API is used with an admin account, this method returns the
* names of the projects that are visible for this user. Otherwise, it returns
* all project names that are known.
*
* @param mail
* the e-mail address of the user for which the project names should
* be retrieved
* @return a set of project names (including the namespace)
* @throws IOException
* If the Gitlab API throws an IOException
*/
protected Set<String> getProjectsOfUser(String mail) throws IOException {
// If we have admin access
if (api.getUser().isAdmin()) {
GitlabUser user = getUserByMail(mail);
if (user == null) {
LOGGER.warn("Couldn't find user with mail \"{}\". returning empty list of projects.", mail);
return new TreeSet<>();
}
// List<GitlabProject> gitProjects = api.getProjectsViaSudo(user);
List<GitlabProject> gitProjects = getProjectsVisibleForUser(user);
Set<String> projectNames = new HashSet<String>();
for (GitlabProject p : gitProjects) {
projectNames.add(p.getNameWithNamespace());
}
return projectNames;
} else {
// We can not check the access of a single user. Simply return all known
// projects.
return (projectUris != null) ? projectUris : new TreeSet<>();
}
}
示例3: buildGrantedAuthorities
import org.gitlab.api.models.GitlabProject; //导入依赖的package包/类
private Collection<GrantedAuthority> buildGrantedAuthorities(String gitLabUrl, GitlabUser user, String privateToken) throws IOException {
Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
if(user.isAdmin()) {
authorities.add(new GrantedAuthorityImpl(StringUtils.substringBetween(gitLabUrl, "://", "/") + GitLabGrantedAuthority.GITLAB_ADMIN_SUFFIX));
return authorities;
}
if(StringUtils.isBlank(privateToken)) {
return authorities;
}
GitlabAPI gitlabAPI = GitlabAPI.connect(gitLabUrl, privateToken);
List<GitlabProject> projects = gitlabAPI.getProjects();
for (GitlabProject project: projects) {
authorities.add(buildGrantedAuthority(gitlabAPI, project));
}
return authorities;
}
示例4: getMergeRequestSummaries
import org.gitlab.api.models.GitlabProject; //导入依赖的package包/类
@Override
public List<MergeRequestSummary> getMergeRequestSummaries() throws GitLabApiException {
List<MergeRequestSummary> mergeRequestSummaries = new ArrayList<>();
try {
for (GitlabProject project : client.getProjects()) {
for (GitlabMergeRequest mergeRequest : client.getOpenMergeRequests(project)) {
List<GitlabNote> notes = client.getAllNotes(mergeRequest);
mergeRequestSummaries.add(new MergeRequestSummary(project, mergeRequest, notes));
}
}
} catch (IOException e) {
throw new GitLabApiException(e);
}
return mergeRequestSummaries;
}
示例5: getGitlabProjects
import org.gitlab.api.models.GitlabProject; //导入依赖的package包/类
@Override
public List<ProjectSummary> getGitlabProjects() throws GitLabApiException {
List<ProjectSummary> allProjects = new ArrayList<>();
try {
for (GitlabProject project : client.getProjects()) {
allProjects.add(new ProjectSummary(project));
}
} catch (IOException e) {
throw new GitLabApiException(e);
}
checker.check(allProjects);
return allProjects;
}
示例6: getIssue
import org.gitlab.api.models.GitlabProject; //导入依赖的package包/类
public Optional<GitLabIssue> getIssue(String projectName, Integer matchedIssue)
throws GitChangelogIntegrationException {
try {
GitlabAPI gitLabApi = GitlabAPI.connect(hostUrl, apiToken);
GitlabProject project = null;
for (GitlabProject glp : gitLabApi.getProjects()) {
if (glp.getName().equals(projectName)) {
project = glp;
}
}
Integer projectId = project.getId();
List<GitlabIssue> issues =
cache.get(new GitLabProjectIssuesCacheKey(hostUrl, apiToken, projectId));
for (GitlabIssue candidate : issues) {
if (candidate.getIid() == matchedIssue) {
return Optional.of(createGitLabIssue(project.getHttpUrl(), candidate));
}
}
return Optional.absent();
} catch (Exception e) {
throw new GitChangelogIntegrationException(e.getMessage(), e);
}
}
示例7: addProjects
import org.gitlab.api.models.GitlabProject; //导入依赖的package包/类
@Override
public void addProjects( Collection<GitlabProject> projects ) {
DefaultMutableTreeNode root = (DefaultMutableTreeNode) tree.getModel().getRoot();
root.removeAllChildren();
if ( projects == null ) {
return ;
}
Map< Integer, GLNamespaceNode> namespaceNodes = new HashMap<>();
final List< GLProjectNode > projectNodes = new LinkedList<>();
for ( GitlabProject project : projects ) {
GLNamespaceNode rootNodeFor = getRootNodeFor( project, root, namespaceNodes );
GLProjectNode glProjectNode = new GLProjectNode(project);
rootNodeFor.add( glProjectNode );
projectNodes.add( glProjectNode );
}
ProgressManager.getInstance().run( new GetIssuesTask( controller, projectNodes, this ) );
tree.treeDidChange();
tree.expandPath( new TreePath( root.getPath() ) );
}
示例8: getProjects
import org.gitlab.api.models.GitlabProject; //导入依赖的package包/类
public Collection< GitlabProject > getProjects() throws IOException {
checkApi();
SortedSet< GitlabProject > result = new TreeSet<>( new Comparator< GitlabProject >() {
@Override
public int compare(GitlabProject o1, GitlabProject o2) {
GitlabNamespace namespace1 = o1.getNamespace();
String n1 = namespace1 != null ? namespace1.getName().toLowerCase() : "Default";
GitlabNamespace namespace2 = o2.getNamespace();
String n2 = namespace2 != null ? namespace2.getName().toLowerCase() : "Default";
int compareNamespace = n1.compareTo(n2);
return compareNamespace != 0 ? compareNamespace : o1.getName().toLowerCase().compareTo(o2.getName().toLowerCase());
}
} );
List<GitlabProject> projects = api.getProjects();
result.addAll( projects );
return result;
}
示例9: run
import org.gitlab.api.models.GitlabProject; //导入依赖的package包/类
@Override
public void run(@NotNull final ProgressIndicator progressIndicator) {
progressIndicator.setFraction( 0.0 );
progressIndicator.setText( "fetching remote projects" );
try {
final Collection<GitlabProject> projects = controller.getProjects();
progressIndicator.setFraction( 0.5 );
progressIndicator.setText( "got " + ( projects == null ? "0" : projects.size() ) + " projects" );
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
projectsHolder.addProjects( projects );
}
});
progressIndicator.setFraction( 1.0 );
progressIndicator.setText( "get projects done" );
} catch ( IOException e1 ) {
LOG.error( e1 );
}
}
示例10: createProject
import org.gitlab.api.models.GitlabProject; //导入依赖的package包/类
private Uid createProject(Set<Attribute> attributes, OperationOptions options) {
String name = getStringAttr(attributes, Name.NAME);
Integer namespaceId = getAttr(attributes, ATTR_NAMESPACE, Integer.class);
if (namespaceId == null) {
throw new InvalidAttributeValueException("Missing mandatory attribute "+ATTR_NAMESPACE);
}
String description = getStringAttr(attributes, ATTR_DESCRIPTION);
Boolean issuesEnabled = getAttr(attributes, ATTR_ISSUES_ENABLED, Boolean.class);
Boolean wallEnabled = getAttr(attributes, ATTR_WALL_ENABLED, Boolean.class);
Boolean mergeRequestsEnabled = getAttr(attributes, ATTR_MERGE_REQUESTS_ENABLED, Boolean.class);
Boolean wikiEnabled = getAttr(attributes, ATTR_WIKI_ENABLED, Boolean.class);
Boolean snippetsEnabled = getAttr(attributes, ATTR_SNIPPETS_ENABLED, Boolean.class);
Boolean publik = getAttr(attributes, ATTR_PUBLIC, Boolean.class);
Integer visibilityLevel = getAttr(attributes, ATTR_VISIBILITY_LEVEL, Integer.class);
String importUrl = getStringAttr(attributes, ATTR_IMPORT_URL);
try {
GitlabProject gitlabProject = gitlabAPI.createProject(name, namespaceId, description, issuesEnabled, wallEnabled, mergeRequestsEnabled, wikiEnabled, snippetsEnabled, publik, visibilityLevel, importUrl);
Integer id = gitlabProject.getId();
return new Uid(id.toString());
} catch (IOException e) {
throw new ConnectorIOException(e.getMessage(), e);
}
}
示例11: getProjectForPath
import org.gitlab.api.models.GitlabProject; //导入依赖的package包/类
public static GitlabProject getProjectForPath(String path) {
try {
List<GitlabProject> projects = get().getAllProjects();
for (GitlabProject project : projects) {
if (project.getPathWithNamespace().equals(path)) {
return project;
}
}
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Could not retrieve Project with path: {0} (Have you properly configured the project path?)", path);
}
return null;
}
示例12: addRepository
import org.gitlab.api.models.GitlabProject; //导入依赖的package包/类
@Nullable GitLabProject addRepository(@NotNull GitlabProject project) throws IOException, SVNException {
final String projectName = project.getPathWithNamespace();
final String projectKey = StringHelper.normalizeDir(projectName);
final GitLabProject oldProject = mapping.get(projectKey);
if (oldProject == null || oldProject.getProjectId() != project.getId()) {
final File basePath = ConfigHelper.joinPath(context.getBasePath(), config.getPath());
final File 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 VcsRepository repository = config.getTemplate().create(local, repoPath);
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;
}
示例13: testUploadToProject
import org.gitlab.api.models.GitlabProject; //导入依赖的package包/类
@Test
public void testUploadToProject() throws Exception {
GitlabProject project;
try {
project = api.getProject("root", "project");
} catch (FileNotFoundException e) {
project = api.createUserProject(api.getUser().getId(), "project");
}
String content = "test file content";
File tempFile = createTempFile(content);
try {
GitlabUpload upload = api.uploadFile(project, tempFile);
Assert.assertNotNull(upload.getUrl());
} finally {
tempFile.delete();
}
}
示例14: getProjectUrl
import org.gitlab.api.models.GitlabProject; //导入依赖的package包/类
public String getProjectUrl(String projectName) {
Optional<GitlabProject> project;
if (TestConfiguration.gitLabGroupEnabled()) {
// try the projects from assigned group (*-automated)
project = getProjects(getGroupId())
.filter(p -> p.getName().equals(projectName) | p.getName().startsWith(projectName))
.findFirst();
if (!project.isPresent() && getGroupId() != getGroupId(TestConfiguration.gitLabGroup())) {
LOGGER.debug("Couldn't find project {} in assigned group", projectName);
// try the default group
project = getProjects(getGroupId(TestConfiguration.gitLabGroup()))
.filter(p -> p.getName().equals(projectName))
.findFirst();
}
} else {
project = getProjects()
.filter(p -> p.getName().equals(projectName) | p.getName().startsWith(projectName))
.findFirst();
}
if (!project.isPresent()) {
throw new IllegalArgumentException("Project '" + projectName + "' was not found");
}
return project.get().getHttpUrl();
}
示例15: deleteProject
import org.gitlab.api.models.GitlabProject; //导入依赖的package包/类
public boolean deleteProject(String name) {
Stream<GitlabProject> projects = TestConfiguration.gitLabGroupEnabled()? getProjects(getGroupId()) : getProjects();
return projects.filter(p -> p.getName().equals(name) || p.getName().startsWith(name + SEPARATOR))
.map(project -> {
try {
performDeleteProject(project.getId());
IOUtils.deleteDirectory(pathToProject(project.getName()));
LOGGER.debug("Project \"" + name + "\" was deleted");
} catch (IOException e) {
if (e.getMessage()
.startsWith(
"Can not instantiate value of type [simple type, class java.lang.Void]")) {
LOGGER.debug("Project \"" + name + "\" was deleted");
// known exception
LOGGER.trace(
"Catch known exception when deleting project in GitLab",
e);
} else {
LOGGER.error(
"Error when deleting project in GitLab", e);
return false;
}
}
return true;
}).anyMatch(x -> !x);
}