Skip to content

Commit adb7f9e

Browse files
author
epriestley
committed
Add a script to close all open audits in a repository
Summary: If you import a repository you may trigger a large number of irrelevant audits. Provide a tool to nuke them. Test Plan: Ran "audit.php Q" (does not exist), "audit.php P" (phabricator) from various repository states. Reviewers: btrahan Reviewed By: btrahan CC: aran, epriestley Maniphest Tasks: T904, T940 Differential Revision: https://secure.phabricator.com/D1791
1 parent df361a0 commit adb7f9e

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

Diff for: scripts/repository/audit.php

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
/*
5+
* Copyright 2012 Facebook, Inc.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
$root = dirname(dirname(dirname(__FILE__)));
21+
require_once $root.'/scripts/__init_script__.php';
22+
23+
$args = new PhutilArgumentParser($argv);
24+
$args->setTagline('manage open Audit requests');
25+
$args->setSynopsis(<<<EOSYNOPSIS
26+
**audit.php** __repository_callsign__
27+
Close all open audit requests in a repository. This is intended to
28+
reset the state of an imported repository which triggered a bunch of
29+
spurious audit requests during import.
30+
31+
EOSYNOPSIS
32+
);
33+
$args->parseStandardArguments();
34+
$args->parse(
35+
array(
36+
array(
37+
'name' => 'more',
38+
'wildcard' => true,
39+
),
40+
));
41+
42+
$more = $args->getArg('more');
43+
if (count($more) !== 1) {
44+
$args->printHelpAndExit();
45+
}
46+
$callsign = reset($more);
47+
48+
$repository = id(new PhabricatorRepository())->loadOneWhere(
49+
'callsign = %s',
50+
$callsign);
51+
if (!$repository) {
52+
throw new Exception("No repository exists with callsign '{$callsign}'!");
53+
}
54+
55+
$ok = phutil_console_confirm(
56+
'This will reset all open audit requests ("Audit Required" or "Concern '.
57+
'Raised") for commits in this repository to "Audit Not Required". This '.
58+
'operation destroys information and can not be undone! Are you sure '.
59+
'you want to proceed?');
60+
if (!$ok) {
61+
echo "OK, aborting.\n";
62+
die(1);
63+
}
64+
65+
echo "Loading commits...\n";
66+
$all_commits = id(new PhabricatorRepositoryCommit())->loadAllWhere(
67+
'repositoryID = %d',
68+
$repository->getID());
69+
70+
echo "Clearing audit requests...\n";
71+
72+
foreach ($all_commits as $commit) {
73+
$query = id(new PhabricatorAuditQuery())
74+
->withStatus(PhabricatorAuditQuery::STATUS_OPEN)
75+
->withCommitPHIDs(array($commit->getPHID()));
76+
$requests = $query->execute();
77+
78+
echo "Clearing ".$commit->getPHID()."... ";
79+
80+
if (!$requests) {
81+
echo "nothing to do.\n";
82+
continue;
83+
} else {
84+
echo count($requests)." requests to clear";
85+
}
86+
87+
foreach ($requests as $request) {
88+
$request->setAuditStatus(
89+
PhabricatorAuditStatusConstants::AUDIT_NOT_REQUIRED);
90+
$request->save();
91+
echo ".";
92+
}
93+
94+
$commit->setAuditStatus(PhabricatorAuditCommitStatusConstants::NONE);
95+
$commit->save();
96+
echo "\n";
97+
}
98+
99+
echo "Done.\n";

0 commit comments

Comments
 (0)