Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/diffusion/conduit/DiffusionGetLintMessagesConduitAPIMethod.php
12242 views
1
<?php
2
3
final class DiffusionGetLintMessagesConduitAPIMethod
4
extends DiffusionConduitAPIMethod {
5
6
public function getAPIMethodName() {
7
return 'diffusion.getlintmessages';
8
}
9
10
public function getMethodStatus() {
11
return self::METHOD_STATUS_UNSTABLE;
12
}
13
14
public function getMethodDescription() {
15
return pht('Get lint messages for existing code.');
16
}
17
18
protected function defineParamTypes() {
19
return array(
20
'repositoryPHID' => 'required phid',
21
'branch' => 'required string',
22
'commit' => 'optional string',
23
'files' => 'required list<string>',
24
);
25
}
26
27
protected function defineReturnType() {
28
return 'list<dict>';
29
}
30
31
protected function execute(ConduitAPIRequest $request) {
32
$viewer = $request->getUser();
33
34
$repository_phid = $request->getValue('repositoryPHID');
35
$repository = id(new PhabricatorRepositoryQuery())
36
->setViewer($viewer)
37
->withPHIDs(array($repository_phid))
38
->executeOne();
39
40
if (!$repository) {
41
throw new Exception(
42
pht('No repository exists with PHID "%s".', $repository_phid));
43
}
44
45
$branch_name = $request->getValue('branch');
46
if ($branch_name == '') {
47
$repository = id(new PhabricatorRepositoryQuery())
48
->setViewer($request->getUser())
49
->withIDs(array($repository->getID()))
50
->executeOne();
51
$branch_name = $repository->getDefaultArcanistBranch();
52
}
53
54
$branch = id(new PhabricatorRepositoryBranch())->loadOneWhere(
55
'repositoryID = %d AND name = %s',
56
$repository->getID(),
57
$branch_name);
58
if (!$branch || !$branch->getLintCommit()) {
59
return array();
60
}
61
62
$lint_messages = queryfx_all(
63
$branch->establishConnection('r'),
64
'SELECT path, line, code FROM %T WHERE branchID = %d AND path IN (%Ls)',
65
PhabricatorRepository::TABLE_LINTMESSAGE,
66
$branch->getID(),
67
$request->getValue('files'));
68
69
// TODO: Compare commit identifiers of individual files like in
70
// DiffusionBrowseFileController::loadLintMessages().
71
72
return $lint_messages;
73
}
74
75
}
76
77