Example #1
0
  @RequestMapping(value = "/**/pipelineHistory.json", method = RequestMethod.GET)
  public ModelAndView list(
      @RequestParam("pipelineName") String pipelineName,
      @RequestParam(value = "perPage", required = false) Integer perPageParam,
      @RequestParam(value = "start", required = false) Integer startParam,
      HttpServletResponse response,
      HttpServletRequest request)
      throws NamingException {
    PipelineConfig pipelineConfig =
        goConfigService.pipelineConfigNamed(new CaseInsensitiveString(pipelineName));
    String username = CaseInsensitiveString.str(UserHelper.getUserName().getUsername());

    Pagination pagination;
    try {
      pagination =
          Pagination.pageStartingAt(
              startParam, pipelineHistoryService.totalCount(pipelineName), perPageParam);
    } catch (Exception e) {
      Map<String, Object> json = new LinkedHashMap<>();
      addDeveloperErrorMessage(json, e);
      return jsonNotAcceptable(json).respond(response);
    }

    PipelinePauseInfo pauseInfo = pipelinePauseService.pipelinePauseInfo(pipelineName);
    boolean hasBuildCauseInBuffer =
        pipelineScheduleQueue.hasBuildCause(CaseInsensitiveString.str(pipelineConfig.name()));
    PipelineInstanceModels pipelineHistory =
        pipelineHistoryService.load(pipelineName, pagination, username, true);

    boolean hasForcedBuildCause = pipelineScheduleQueue.hasForcedBuildCause(pipelineName);

    PipelineHistoryJsonPresentationModel historyJsonPresenter =
        new PipelineHistoryJsonPresentationModel(
            pauseInfo,
            pipelineHistory,
            pipelineConfig,
            pagination,
            canForce(pipelineConfig, username),
            hasForcedBuildCause,
            hasBuildCauseInBuffer,
            canPause(pipelineConfig, username));
    return jsonFound(historyJsonPresenter.toJson()).respond(response);
  }
Example #2
0
  @Test
  public void shouldDelegateToMaterialRepository_getModificationsFor() {
    GitMaterialConfig materialConfig = new GitMaterialConfig("http://test.com");
    GitMaterialInstance gitMaterialInstance =
        new GitMaterialInstance("http://test.com", null, null, "flyweight");
    Pagination pagination = Pagination.pageStartingAt(0, 10, 10);
    Modifications modifications = new Modifications();
    modifications.add(new Modification("user", "comment", "email", new Date(), "revision"));

    when(materialRepository.findMaterialInstance(materialConfig)).thenReturn(gitMaterialInstance);

    when(materialRepository.getModificationsFor(gitMaterialInstance, pagination))
        .thenReturn(modifications);

    Modifications gotModifications =
        materialService.getModificationsFor(materialConfig, pagination);

    assertThat(gotModifications, is(modifications));
  }
 private Pagination pagination() {
   return Pagination.pageStartingAt(START, COUNT, PER_PAGE);
 }