Return an array of builds for a given project and commit ID.
@param $projectId
@param $commitId
@return array
772311
public function getByProjectAndCommit($projectId, $commitId)
    {
        $query = 'SELECT * FROM `build` WHERE `project_id` = :project_id AND `commit_id` = :commit_id';
        $stmt = Database::getConnection('read')->prepare($query);
        $stmt->bindValue(':project_id', $projectId);
        $stmt->bindValue(':commit_id', $commitId);

        if ($stmt->execute()) {
            $res = $stmt->fetchAll(\PDO::FETCH_ASSOC);

            $map = function ($item) {
                return new Build($item);
            };

            $rtn = array_map($map, $res);

            return array('items' => $rtn, 'count' => count($rtn));
        } else {
            return array('items' => array(), 'count' => 0);
        }
    }
156099
function compileProjectWithId(projectId) {
	return fetchProject(projectId)
	.then(compileProject)
	.catch((error) => {
		console.trace(error);
		throw error;
	});
}
832754
public function listGistsCommits(string $id): array
    {
        return $this->getApi()->request($this->getApi()->sprintf('/gists/:id/commits', $id));
    }
1067249
public function rebuild($buildId)
    {
        $copy   = BuildFactory::getBuildById($buildId);

        if (empty($copy)) {
            throw new NotFoundException(Lang::get('build_x_not_found', $buildId));
        }

        $build = $this->buildService->createDuplicateBuild($copy);

        if ($this->buildService->queueError) {
            $_SESSION['global_error'] = Lang::get('add_to_queue_failed');
        }

        $response = new b8\Http\Response\RedirectResponse();
        $response->setHeader('Location', PHPCI_URL.'build/view/' . $build->getId());
        return $response;
    }
522809
public function fetchBuilds(Repository $repository)
    {
        $response = $this->getResponse(
            sprintf('/repos/%s/builds',$repository->getSlug()),
            array());

        if (is_array($response)) {
            // Load project builds
            foreach ($response as $buildData) {
                $build = new Build();
                // Add build to repository instance
                $repository->addBuild($this->hydrate($build, $buildData));
            }
        }

        return $repository;
    }
1036628
public function setProjectId($projectId = '')
    {
        $this->projectId = $projectId;
        $this->_debug->info(__FUNCTION__, 'setProjectId: ', $this->projectId);
    }
1090378
public function view($projectId)
    {
        $branch = $this->getParam('branch', '');
        $project = $this->projectStore->getById($projectId);

        if (empty($project)) {
            throw new NotFoundException(Lang::get('project_x_not_found', $projectId));
        }

        $per_page = 10;
        $page     = $this->getParam('p', 1);
        $builds   = $this->getLatestBuildsHtml($projectId, urldecode($branch), (($page - 1) * $per_page));
        $pages    = $builds[1] == 0 ? 1 : ceil($builds[1] / $per_page);

        if ($page > $pages) {
            $response = new b8\Http\Response\RedirectResponse();
            $response->setHeader('Location', PHPCI_URL.'project/view/'.$projectId);
            return $response;
        }

        $this->view->builds   = $builds[0];
        $this->view->total    = $builds[1];
        $this->view->project  = $project;
        $this->view->branch   = urldecode($branch);
        $this->view->branches = $this->projectStore->getKnownBranches($projectId);
        $this->view->page     = $page;
        $this->view->pages    = $pages;

        $this->layout->title = $project->getTitle();
        $this->layout->subtitle = $this->view->branch;

        return $this->view->render();
    }
1294595
public function enableProjects($enable, $project_id)
    {
        $enable = $enable === 'true';

        $projects = $project_id == 'all'
            ? Project::all()
            : Project::where('id', $project_id)->get();

        foreach ($projects as $test) {
            $this->enableProject($enable, $test);
        }

        return $enable;
    }
145832
public RunT getBuild(String id) {
        for (RunT r : _getRuns().values()) {
            if (r.getId().equals(id))
                return r;
        }
        return null;
    }
14968
public function createComment(int $number, string $body, string $commitId, string $path, int $position): array
    {
        return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/pulls/:number/comments',
            $this->getPullRequests()->getOwner(), $this->getPullRequests()->getRepo(), $number), Request::METHOD_POST, [
                'body'      => $body,
                'commit_id' => $commitId,
                'path'      => $path,
                'position'  => $position
            ]);
    }
1120819
public function getDocumentRoot(string $buildId = null): ?string
    {
        $documentRoot = $this->getCodePath($buildId);

        if ($this->getRelativeDocumentRoot()) {
            $documentRoot .= '/' . $this->getRelativeDocumentRoot();
        }

        return $documentRoot;
    }
736151
public function commentOnProject($projectId = null, $text = "")
    {
        $projectId = $projectId ?: $this->defaultProjectId;

        $data = [
            "text" => $text
        ];

        return $this->curl->post("projects/{$projectId}/stories", ['data' => $data]);
    }
530529
public QueryBuilder withCommitId(BigDecimal commitId) {
        Validate.argumentIsNotNull(commitId);
        queryParamsBuilder.commitId(CommitId.valueOf(commitId));
        return this;
    }
100157
public List<GitlabCommit> getAllCommits(Serializable projectId) throws IOException {
        return getAllCommits(projectId, null, null);
    }
585516
private Map<String, Commit> buildRevisionNumberToCommitMap(List<Commit> commits) {
		Map<String, Commit> rt = new HashMap<>();
		
		for (Commit commit : commits) {
			String revisionNumber = commit.getScmRevisionNumber();
			
			boolean alreadyExists = rt.put(revisionNumber, commit) != null;
			
			if (alreadyExists) {
				logger.warn("Error encountered building pipeline: multiple commits exist for revision number " + revisionNumber);
			}
		}
		
		return rt;
	}
554669
@RequestMapping(value = "project/{projectId}/builds/diff", method = RequestMethod.GET)
    public Resources<Action> buildDiffActions(@PathVariable ID projectId) {
        return Resources.of(
                extensionManager.getExtensions(BuildDiffExtension.class)
                        .stream()
                        .filter(extension -> extension.apply(structureService.getProject(projectId)))
                        .map(this::resolveExtensionAction)
                        .collect(Collectors.toList()),
                uri(on(getClass()).buildDiffActions(projectId))
        );
    }
822827
public function bitbucket($projectId)
    {
        $project = $this->fetchProject($projectId, 'bitbucket');
    
        // Support both old services and new webhooks
        if ($payload = $this->getParam('payload')) {
            return $this->bitbucketService(json_decode($payload, true), $project);
        }

        $payload = json_decode(file_get_contents("php://input"), true);

        if (empty($payload['push']['changes'])) {
            // Invalid event from bitbucket
            return [
                'status' => 'failed',
                'commits' => []
            ];
        }

        return $this->bitbucketWebhook($payload, $project);
    }