Skip to content

Commit f8b7f03

Browse files
committedMay 18, 2015
Change "lint save" to not use Arcanist Projects
Summary: Ref T7604. Change `DiffusionLintSaveRunner` to use repositories instead of Arcanist Projects. Test Plan: Ran the `save_lint.php` script and queried results using the `diffusion.getlintmessages` Conduit endpoint. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin, epriestley Maniphest Tasks: T7604 Differential Revision: https://secure.phabricator.com/D12893
1 parent 898ce6b commit f8b7f03

File tree

3 files changed

+49
-26
lines changed

3 files changed

+49
-26
lines changed
 

‎scripts/repository/save_lint.php

+11-8
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,38 @@
1717
->parse(array(
1818
array(
1919
'name' => 'all',
20-
'help' =>
20+
'help' => pht(
2121
'Discover problems in the whole repository instead of just changes '.
22-
'since the last run.',
22+
'since the last run.'),
2323
),
2424
array(
2525
'name' => 'arc',
2626
'param' => 'path',
2727
'default' => 'arc',
28-
'help' => 'Path to Arcanist executable.',
28+
'help' => pht('Path to Arcanist executable.'),
2929
),
3030
array(
3131
'name' => 'severity',
3232
'param' => 'string',
3333
'default' => ArcanistLintSeverity::SEVERITY_ADVICE,
34-
'help' => 'Minimum severity, one of ArcanistLintSeverity constants.',
34+
'help' => pht(
35+
'Minimum severity, one of %s constants.',
36+
'ArcanistLintSeverity'),
3537
),
3638
array(
3739
'name' => 'chunk-size',
3840
'param' => 'number',
3941
'default' => 256,
40-
'help' => 'Number of paths passed to `arc` at once.',
42+
'help' => pht('Number of paths passed to `%s` at once.', 'arc'),
4143
),
4244
array(
4345
'name' => 'blame',
44-
'help' => 'Assign lint errors to authors who last modified the line.',
46+
'help' => pht(
47+
'Assign lint errors to authors who last modified the line.'),
4548
),
4649
));
4750

48-
echo "Saving lint errors to database...\n";
51+
echo pht('Saving lint errors to database...')."\n";
4952

5053
$count = id(new DiffusionLintSaveRunner())
5154
->setAll($args->getArg('all', false))
@@ -55,4 +58,4 @@
5558
->setNeedsBlame($args->getArg('blame'))
5659
->run('.');
5760

58-
echo "\nProcessed {$count} files.\n";
61+
echo "\n".pht('Processed %d files.', $count)."\n";

‎src/applications/diffusion/DiffusionLintSaveRunner.php

+20-6
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,31 @@ public function run($dir) {
5858
}
5959
}
6060

61-
$project_id = $working_copy->getProjectID();
62-
$project = id(new PhabricatorRepositoryArcanistProject())
63-
->loadOneWhere('name = %s', $project_id);
64-
if (!$project || !$project->getRepositoryID()) {
65-
throw new Exception("Couldn't find repository for {$project_id}.");
61+
$callsign = $configuration_manager->getConfigFromAnySource(
62+
'repository.callsign');
63+
$uuid = $api->getRepositoryUUID();
64+
$remote_uri = $api->getRemoteURI();
65+
66+
$repository_query = id(new PhabricatorRepositoryQuery())
67+
->setViewer(PhabricatorUser::getOmnipotentUser());
68+
69+
if ($callsign) {
70+
$repository_query->withCallsigns(array($callsign));
71+
} else if ($uuid) {
72+
$repository_query->withUUIDs(array($uuid));
73+
} else if ($remote_uri) {
74+
$repository_query->withRemoteURIs(array($remote_uri));
6675
}
6776

77+
$repository = $repository_query->executeOne();
6878
$branch_name = $api->getBranchName();
6979

80+
if (!$repository) {
81+
throw new Exception(pht('No repository was found.'));
82+
}
83+
7084
$this->branch = PhabricatorRepositoryBranch::loadOrCreateBranch(
71-
$project->getRepositoryID(),
85+
$repository->getID(),
7286
$branch_name);
7387
$this->conn = $this->branch->establishConnection('w');
7488

‎src/applications/diffusion/conduit/DiffusionGetLintMessagesConduitAPIMethod.php

+18-12
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ public function getMethodStatus() {
1212
}
1313

1414
public function getMethodDescription() {
15-
return 'Get lint messages for existing code.';
15+
return pht('Get lint messages for existing code.');
1616
}
1717

1818
protected function defineParamTypes() {
1919
return array(
20-
'arcanistProject' => 'required string',
21-
'branch' => 'optional string',
22-
'commit' => 'optional string',
23-
'files' => 'required list<string>',
20+
'repositoryPHID' => 'required phid',
21+
'branch' => 'required string',
22+
'commit' => 'optional string',
23+
'files' => 'required list<string>',
2424
);
2525
}
2626

@@ -29,25 +29,31 @@ protected function defineReturnType() {
2929
}
3030

3131
protected function execute(ConduitAPIRequest $request) {
32-
$project = id(new PhabricatorRepositoryArcanistProject())->loadOneWhere(
33-
'name = %s',
34-
$request->getValue('arcanistProject'));
35-
if (!$project || !$project->getRepositoryID()) {
36-
return array();
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));
3743
}
3844

3945
$branch_name = $request->getValue('branch');
4046
if ($branch_name == '') {
4147
$repository = id(new PhabricatorRepositoryQuery())
4248
->setViewer($request->getUser())
43-
->withIDs(array($project->getRepositoryID()))
49+
->withIDs(array($repository->getID()))
4450
->executeOne();
4551
$branch_name = $repository->getDefaultArcanistBranch();
4652
}
4753

4854
$branch = id(new PhabricatorRepositoryBranch())->loadOneWhere(
4955
'repositoryID = %d AND name = %s',
50-
$project->getRepositoryID(),
56+
$repository->getID(),
5157
$branch_name);
5258
if (!$branch || !$branch->getLintCommit()) {
5359
return array();

0 commit comments

Comments
 (0)
Failed to load comments.