Merge pull request #1200 from scm-manager/feature/shortened_commit_id

find single changeset for shortened changesetId
This commit is contained in:
Sebastian Sdorra
2020-06-17 17:26:12 +02:00
committed by GitHub
3 changed files with 27 additions and 23 deletions

View File

@@ -204,7 +204,7 @@ export default function reducer(
...state[_key],
byId: {
..._oldByIds,
[changeset.id]: changeset
[payload.id]: changeset
}
}
};

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.api.v2.resources;
import io.swagger.v3.oas.annotations.Operation;
@@ -48,7 +48,9 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.util.Optional;
import static sonia.scm.ContextEntry.ContextBuilder.entity;
import static sonia.scm.NotFoundException.notFound;
@Slf4j
@@ -150,19 +152,11 @@ public class ChangesetRootResource {
try (RepositoryService repositoryService = serviceFactory.create(new NamespaceAndName(namespace, name))) {
Repository repository = repositoryService.getRepository();
RepositoryPermissions.read(repository).check();
ChangesetPagingResult changesets = repositoryService.getLogCommand()
.setStartChangeset(id)
.setEndChangeset(id)
.getChangesets();
if (changesets != null && changesets.getChangesets() != null && !changesets.getChangesets().isEmpty()) {
Optional<Changeset> changeset = changesets.getChangesets().stream().filter(ch -> ch.getId().equals(id)).findFirst();
if (!changeset.isPresent()) {
return Response.status(Response.Status.NOT_FOUND).build();
}
return Response.ok(changesetToChangesetDtoMapper.map(changeset.get(), repository)).build();
} else {
return Response.status(Response.Status.NOT_FOUND).build();
Changeset changeset = repositoryService.getLogCommand().getChangeset(id);
if (changeset == null) {
throw notFound(entity(Changeset.class, id).in(repository));
}
return Response.ok(changesetToChangesetDtoMapper.map(changeset, repository)).build();
}
}
}

View File

@@ -176,24 +176,34 @@ public class ChangesetRootResourceTest extends RepositoryTestBase {
String authorName = "name";
String authorEmail = "em@i.l";
String commit = "my branch commit";
ChangesetPagingResult changesetPagingResult = mock(ChangesetPagingResult.class);
List<Changeset> changesetList = Lists.newArrayList(new Changeset(id, Date.from(creationDate).getTime(), new Person(authorName, authorEmail), commit));
when(changesetPagingResult.getChangesets()).thenReturn(changesetList);
when(changesetPagingResult.getTotal()).thenReturn(1);
when(logCommandBuilder.setEndChangeset(anyString())).thenReturn(logCommandBuilder);
when(logCommandBuilder.setStartChangeset(anyString())).thenReturn(logCommandBuilder);
when(logCommandBuilder.getChangesets()).thenReturn(changesetPagingResult);
when(logCommandBuilder.getChangeset(id)).thenReturn(
new Changeset(id, Date.from(creationDate).getTime(), new Person(authorName, authorEmail), commit)
);
MockHttpRequest request = MockHttpRequest
.get(CHANGESET_URL + id)
.accept(VndMediaType.CHANGESET);
MockHttpResponse response = new MockHttpResponse();
dispatcher.invoke(request, response);
assertEquals(200, response.getStatus());
log.info("Response :{}", response.getContentAsString());
assertTrue(response.getContentAsString().contains(String.format("\"id\":\"%s\"", id)));
assertTrue(response.getContentAsString().contains(String.format("\"name\":\"%s\"", authorName)));
assertTrue(response.getContentAsString().contains(String.format("\"mail\":\"%s\"", authorEmail)));
assertTrue(response.getContentAsString().contains(String.format("\"description\":\"%s\"", commit)));
}
@Test
public void shouldReturnNotFoundForNonExistingChangeset() throws Exception {
MockHttpRequest request = MockHttpRequest
.get(CHANGESET_URL + "abcd")
.accept(VndMediaType.CHANGESET);
MockHttpResponse response = new MockHttpResponse();
dispatcher.invoke(request, response);
assertEquals(404, response.getStatus());
}
}