use of com.google.gerrit.extensions.api.projects.TagInfo in project gerrit by GerritCodeReview.
the class ListTags method apply.
@Override
public List<TagInfo> apply(ProjectResource resource) throws IOException, ResourceNotFoundException, BadRequestException {
List<TagInfo> tags = new ArrayList<>();
PermissionBackend.ForProject perm = permissionBackend.user(user).project(resource.getNameKey());
try (Repository repo = getRepository(resource.getNameKey());
RevWalk rw = new RevWalk(repo)) {
ProjectControl pctl = resource.getControl();
Map<String, Ref> all = visibleTags(pctl, repo, repo.getRefDatabase().getRefs(Constants.R_TAGS));
for (Ref ref : all.values()) {
tags.add(createTagInfo(perm.ref(ref.getName()), ref, rw));
}
}
Collections.sort(tags, new Comparator<TagInfo>() {
@Override
public int compare(TagInfo a, TagInfo b) {
return a.ref.compareTo(b.ref);
}
});
return new RefFilter<TagInfo>(Constants.R_TAGS).start(start).limit(limit).subString(matchSubstring).regex(matchRegex).filter(tags);
}
use of com.google.gerrit.extensions.api.projects.TagInfo in project gerrit by GerritCodeReview.
the class ListTags method apply.
@Override
public Response<ImmutableList<TagInfo>> apply(ProjectResource resource) throws IOException, ResourceNotFoundException, RestApiException, PermissionBackendException {
resource.getProjectState().checkStatePermitsRead();
List<TagInfo> tags = new ArrayList<>();
PermissionBackend.ForProject perm = permissionBackend.currentUser().project(resource.getNameKey());
try (Repository repo = getRepository(resource.getNameKey());
RevWalk rw = new RevWalk(repo)) {
Collection<Ref> all = visibleTags(resource.getNameKey(), repo, repo.getRefDatabase().getRefsByPrefix(Constants.R_TAGS));
for (Ref ref : all) {
tags.add(createTagInfo(perm.ref(ref.getName()), ref, rw, resource.getProjectState(), links));
}
}
tags.sort(comparing(t -> t.ref));
return Response.ok(new RefFilter<TagInfo>(Constants.R_TAGS).start(start).limit(limit).subString(matchSubstring).regex(matchRegex).filter(tags));
}
use of com.google.gerrit.extensions.api.projects.TagInfo in project gerrit by GerritCodeReview.
the class ListTags method createTagInfo.
// TODO(issue-15517): Fix the JdkObsolete issue with Date once JGit's PersonIdent class supports
// Instants
@SuppressWarnings("JdkObsolete")
public static TagInfo createTagInfo(PermissionBackend.ForRef perm, Ref ref, RevWalk rw, ProjectState projectState, WebLinks links) throws IOException {
RevObject object = rw.parseAny(ref.getObjectId());
Boolean canDelete = null;
if (!isConfigRef(ref.getName())) {
// Never allow to delete the meta config branch.
canDelete = perm.testOrFalse(RefPermission.DELETE) && projectState.statePermitsWrite() ? true : null;
}
ImmutableList<WebLinkInfo> webLinks = links.getTagLinks(projectState.getName(), ref.getName());
if (object instanceof RevTag) {
// Annotated or signed tag
RevTag tag = (RevTag) object;
PersonIdent tagger = tag.getTaggerIdent();
return new TagInfo(ref.getName(), tag.getName(), tag.getObject().getName(), tag.getFullMessage().trim(), tagger != null ? CommonConverters.toGitPerson(tagger) : null, canDelete, webLinks.isEmpty() ? null : webLinks, tagger != null ? tagger.getWhen().toInstant() : null);
}
Instant timestamp = object instanceof RevCommit ? ((RevCommit) object).getCommitterIdent().getWhen().toInstant() : null;
// Lightweight tag
return new TagInfo(ref.getName(), ref.getObjectId().getName(), canDelete, webLinks.isEmpty() ? null : webLinks, timestamp);
}
use of com.google.gerrit.extensions.api.projects.TagInfo in project gerrit by GerritCodeReview.
the class TagsIT method annotatedTag.
@Test
public void annotatedTag() throws Exception {
grantTagPermissions();
PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo);
PushOneCommit.Result r = push.to("refs/heads/master");
r.assertOkStatus();
TagInput input = new TagInput();
input.ref = "v1.0";
input.revision = r.getCommit().getName();
input.message = "annotation message";
TagInfo result = tag(input.ref).create(input).get();
assertThat(result.ref).isEqualTo(R_TAGS + input.ref);
assertThat(result.object).isEqualTo(input.revision);
assertThat(result.message).isEqualTo(input.message);
assertThat(result.tagger.name).isEqualTo(admin.fullName());
assertThat(result.tagger.email).isEqualTo(admin.email());
assertThat(result.created).isEqualTo(result.tagger.date);
eventRecorder.assertRefUpdatedEvents(project.get(), result.ref, null, result.revision);
// A second tag pushed on the same ref should have the same ref
TagInput input2 = new TagInput();
input2.ref = "refs/tags/v2.0";
input2.revision = input.revision;
input2.message = "second annotation message";
TagInfo result2 = tag(input2.ref).create(input2).get();
assertThat(result2.ref).isEqualTo(input2.ref);
assertThat(result2.object).isEqualTo(input2.revision);
assertThat(result2.message).isEqualTo(input2.message);
assertThat(result2.tagger.name).isEqualTo(admin.fullName());
assertThat(result2.tagger.email).isEqualTo(admin.email());
assertThat(result2.created).isEqualTo(result2.tagger.date);
eventRecorder.assertRefUpdatedEvents(project.get(), result2.ref, null, result2.revision);
}
use of com.google.gerrit.extensions.api.projects.TagInfo in project gerrit by GerritCodeReview.
the class TagsIT method createTags.
private void createTags() throws Exception {
grantTagPermissions();
String revision = pushTo("refs/heads/master").getCommit().name();
TagInput input = new TagInput();
input.revision = revision;
for (String tagname : testTags) {
TagInfo result = tag(tagname).create(input).get();
assertThat(result.revision).isEqualTo(input.revision);
assertThat(result.ref).isEqualTo(R_TAGS + tagname);
}
}
Aggregations