use of org.gitlab4j.api.models.Tag in project legend-sdlc by finos.
the class GitLabVersionApi method getVersions.
private Stream<Version> getVersions(GitLabProjectId projectId, Integer minMajorVersion, Integer maxMajorVersion, Integer minMinorVersion, Integer maxMinorVersion, Integer minPatchVersion, Integer maxPatchVersion) {
switch(getProjectTypeFromMode(projectId.getGitLabMode())) {
case PROTOTYPE:
{
return Stream.empty();
}
case PRODUCTION:
{
try {
Stream<Version> stream = PagerTools.stream(getGitLabApi(projectId.getGitLabMode()).getTagsApi().getTags(projectId.getGitLabId(), ITEMS_PER_PAGE)).filter(GitLabVersionApi::isVersionTag).map(tag -> fromGitLabTag(projectId.toString(), tag));
// major version constraint
if ((minMajorVersion != null) && (maxMajorVersion != null)) {
int minMajorVersionInt = minMajorVersion;
int maxMajorVersionInt = maxMajorVersion;
if (minMajorVersionInt == maxMajorVersionInt) {
stream = stream.filter(v -> v.getId().getMajorVersion() == minMajorVersionInt);
} else {
stream = stream.filter(v -> {
int majorVersion = v.getId().getMajorVersion();
return (minMajorVersionInt <= majorVersion) && (majorVersion <= maxMajorVersionInt);
});
}
} else if (minMajorVersion != null) {
int minMajorVersionInt = minMajorVersion;
stream = stream.filter(v -> v.getId().getMajorVersion() >= minMajorVersionInt);
} else if (maxMajorVersion != null) {
int maxMajorVersionInt = maxMajorVersion;
stream = stream.filter(v -> v.getId().getMajorVersion() <= maxMajorVersionInt);
}
// minor version constraint
if ((minMinorVersion != null) && (maxMinorVersion != null)) {
int minMinorVersionInt = minMinorVersion;
int maxMinorVersionInt = maxMinorVersion;
if (minMinorVersionInt == maxMinorVersionInt) {
stream = stream.filter(v -> v.getId().getMinorVersion() == minMinorVersionInt);
} else {
stream = stream.filter(v -> {
int minorVersion = v.getId().getMinorVersion();
return (minMinorVersionInt <= minorVersion) && (minorVersion <= maxMinorVersionInt);
});
}
} else if (minMinorVersion != null) {
int minMinorVersionInt = minMinorVersion;
stream = stream.filter(v -> v.getId().getMinorVersion() >= minMinorVersionInt);
} else if (maxMinorVersion != null) {
int maxMinorVersionInt = maxMinorVersion;
stream = stream.filter(v -> v.getId().getMinorVersion() <= maxMinorVersionInt);
}
// patch version constraint
if ((minPatchVersion != null) && (maxPatchVersion != null)) {
int minPatchVersionInt = minPatchVersion;
int maxPatchVersionInt = maxPatchVersion;
if (minPatchVersionInt == maxPatchVersionInt) {
stream = stream.filter(v -> v.getId().getPatchVersion() == minPatchVersionInt);
} else {
stream = stream.filter(v -> {
int patchVersion = v.getId().getPatchVersion();
return (minPatchVersionInt <= patchVersion) && (patchVersion <= maxPatchVersionInt);
});
}
} else if (minPatchVersion != null) {
int minPatchVersionInt = minPatchVersion;
stream = stream.filter(v -> v.getId().getPatchVersion() >= minPatchVersionInt);
} else if (maxPatchVersion != null) {
int maxPatchVersionInt = maxPatchVersion;
stream = stream.filter(v -> v.getId().getPatchVersion() <= maxPatchVersionInt);
}
return stream;
} catch (Exception e) {
throw buildException(e, () -> "User " + getCurrentUser() + " is not allowed to get versions for project " + projectId, () -> "Unknown project: " + projectId, () -> "Error getting versions for project " + projectId);
}
}
default:
{
throw new LegendSDLCServerException("Unknown project: " + projectId, Status.BAD_REQUEST);
}
}
}
use of org.gitlab4j.api.models.Tag in project legend-sdlc by finos.
the class GitLabVersionApi method newVersion.
private Version newVersion(GitLabProjectId projectId, String revisionId, VersionId versionId, String notes) {
String tagName = buildVersionTagName(versionId);
String message = "Release tag for version " + versionId.toVersionIdString();
try {
GitLabApi gitLabApi = getGitLabApi(projectId.getGitLabMode());
CommitsApi commitsApi = gitLabApi.getCommitsApi();
Commit referenceCommit;
if (revisionId == null) {
referenceCommit = commitsApi.getCommit(projectId.getGitLabId(), MASTER_BRANCH);
if (referenceCommit == null) {
throw new LegendSDLCServerException("Cannot create version " + versionId.toVersionIdString() + " of project " + projectId + ": cannot find current revision (project may be corrupt)", Status.INTERNAL_SERVER_ERROR);
}
} else {
try {
referenceCommit = commitsApi.getCommit(projectId.getGitLabId(), revisionId);
} catch (GitLabApiException e) {
if (GitLabApiTools.isNotFoundGitLabApiException(e)) {
throw new LegendSDLCServerException("Revision " + revisionId + " is unknown in project " + projectId, Status.BAD_REQUEST);
}
throw e;
}
Pager<CommitRef> referenceCommitBranchPager = withRetries(() -> commitsApi.getCommitRefs(projectId.getGitLabId(), referenceCommit.getId(), RefType.BRANCH, ITEMS_PER_PAGE));
Stream<CommitRef> referenceCommitBranches = PagerTools.stream(referenceCommitBranchPager);
if (referenceCommitBranches.noneMatch(ref -> MASTER_BRANCH.equals(ref.getName()))) {
throw new LegendSDLCServerException("Revision " + revisionId + " is unknown in project " + projectId, Status.BAD_REQUEST);
}
}
String referenceRevisionId = referenceCommit.getId();
Pager<CommitRef> referenceCommitTagPager = withRetries(() -> commitsApi.getCommitRefs(projectId.getGitLabId(), referenceRevisionId, RefType.TAG, ITEMS_PER_PAGE));
List<CommitRef> referenceCommitTags = PagerTools.stream(referenceCommitTagPager).collect(Collectors.toList());
if (referenceCommitTags.stream().map(CommitRef::getName).anyMatch(GitLabVersionApi::isVersionTagName)) {
StringBuilder builder = new StringBuilder("Revision ").append(referenceRevisionId).append(" has already been released in ");
List<VersionId> revisionVersionIds = referenceCommitTags.stream().map(CommitRef::getName).filter(GitLabVersionApi::isVersionTagName).map(GitLabVersionApi::parseVersionTagName).collect(Collectors.toList());
if (revisionVersionIds.size() == 1) {
builder.append("version ");
revisionVersionIds.get(0).appendVersionIdString(builder);
} else {
builder.append("versions ");
revisionVersionIds.sort(Comparator.naturalOrder());
boolean first = true;
for (VersionId revisionVersionId : revisionVersionIds) {
if (first) {
first = false;
} else {
builder.append(", ");
}
revisionVersionId.appendVersionIdString(builder);
}
}
throw new LegendSDLCServerException(builder.toString());
}
Tag tag = getGitLabApi(projectId.getGitLabMode()).getTagsApi().createTag(projectId.getGitLabId(), tagName, referenceRevisionId, message, notes);
return fromGitLabTag(projectId.toString(), tag);
} catch (Exception e) {
throw buildException(e, () -> "User " + getCurrentUser() + " is not allowed to create version " + versionId.toVersionIdString() + " of project " + projectId, () -> "Unknown project: " + projectId, () -> "Error creating version " + versionId.toVersionIdString() + " of project " + projectId);
}
}
use of org.gitlab4j.api.models.Tag in project choerodon-starters by open-hand.
the class RepositoryApi method updateTagRelease.
/**
* Updates the release notes of a given release.
* <p>
* PUT /projects/:id/repository/tags/:tag_name/release
*
* @param projectId the ID of the project
* @param tagName The name of the tag Must be unique for the project
* @param releaseNotes the release notes for the tag
* @return a Tag instance containing release notes on the newly updated tag
* @throws GitLabApiException if any exception occurs
*/
public Tag updateTagRelease(Integer projectId, String tagName, String releaseNotes) throws GitLabApiException {
Form formData = new GitLabApiForm().withParam("description", releaseNotes, true);
Response response = put(Response.Status.OK, formData.asMap(), "projects", projectId, "repository", "tags", tagName, "release");
return (response.readEntity(Tag.class));
}
use of org.gitlab4j.api.models.Tag in project choerodon-starters by open-hand.
the class RepositoryApi method createTag.
/**
* Creates a tag on a particular ref of the given project. A message and release notes are optional.
* <p>
* POST /projects/:id/repository/tags
*
* @param projectId the ID of the project
* @param tagName The name of the tag Must be unique for the project
* @param ref the git ref to place the tag on
* @param message the message to included with the tag (optional)
* @param releaseNotes the release notes for the tag (optional)
* @return a Tag instance containing info on the newly created tag
* @throws GitLabApiException if any exception occurs
*/
public Tag createTag(Integer projectId, String tagName, String ref, String message, String releaseNotes) throws GitLabApiException {
Form formData = new GitLabApiForm().withParam("tag_name", tagName, true).withParam("ref", ref, true).withParam("message", message, false).withParam("release_description", releaseNotes, false);
Response response = post(Response.Status.CREATED, formData.asMap(), "projects", projectId, "repository", "tags");
return (response.readEntity(Tag.class));
}
use of org.gitlab4j.api.models.Tag in project legend-sdlc by finos.
the class GitLabRevisionApi method getRevisionStatus.
@Override
public RevisionStatus getRevisionStatus(String projectId, String revisionId) {
LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null");
LegendSDLCServerException.validateNonNull(revisionId, "revisionId may not be null");
GitLabProjectId gitLabProjectId = parseProjectId(projectId);
try {
GitLabApi gitLabApi = getGitLabApi(gitLabProjectId.getGitLabMode());
CommitsApi commitsApi = gitLabApi.getCommitsApi();
Revision revision = getProjectRevisionContext(projectId).getRevision(revisionId);
Pager<CommitRef> commitRefPager = withRetries(() -> commitsApi.getCommitRefs(gitLabProjectId.getGitLabId(), revision.getId(), RefType.ALL, ITEMS_PER_PAGE));
List<CommitRef> commitRefs = PagerTools.stream(commitRefPager).collect(Collectors.toList());
boolean isCommitted = commitRefs.stream().anyMatch(cr -> MASTER_BRANCH.equals(cr.getName()));
List<Version> versions;
List<String> versionTagNames = commitRefs.stream().filter(cr -> (RefType.TAG == cr.getType()) && isVersionTagName(cr.getName())).map(CommitRef::getName).collect(Collectors.toList());
if (versionTagNames.isEmpty()) {
versions = Collections.emptyList();
} else {
TagsApi tagsApi = gitLabApi.getTagsApi();
versions = Lists.mutable.ofInitialCapacity(versionTagNames.size());
for (String tagName : versionTagNames) {
Tag tag = withRetries(() -> tagsApi.getTag(gitLabProjectId.getGitLabId(), tagName));
versions.add(fromGitLabTag(projectId, tag));
}
versions.sort(Comparator.comparing(Version::getId));
}
List<Workspace> workspaces;
if (isCommitted) {
workspaces = Collections.emptyList();
} else {
// Note that here we will not account for conflict resolution or backup branch because in the model those are not real workspaces.
workspaces = commitRefs.stream().filter(cr -> (RefType.BRANCH == cr.getType()) && isWorkspaceBranchName(cr.getName(), ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE)).map(cr -> fromWorkspaceBranchName(projectId, cr.getName(), WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE)).collect(Collectors.toList());
}
return new RevisionStatus() {
@Override
public Revision getRevision() {
return revision;
}
@Override
public boolean isCommitted() {
return isCommitted;
}
@Override
public List<Workspace> getWorkspaces() {
return workspaces;
}
@Override
public List<Version> getVersions() {
return versions;
}
};
} catch (Exception e) {
throw buildException(e, () -> "User " + getCurrentUser() + " is not allowed to access the status for revision " + revisionId + " of project " + projectId, () -> "Unknown: revision " + revisionId + " of project " + projectId, () -> "Error getting the status for revision " + revisionId + " of project " + projectId);
}
}
Aggregations