Skip to content

Commit fa8f168

Browse files
author
epriestley
committed
Allow commits to be marked as 'bad' so they won't be parsed. Useful if you work
at a company where someone deleted the entire repository *cough cough*.
1 parent 1a11297 commit fa8f168

File tree

8 files changed

+114
-14
lines changed

8 files changed

+114
-14
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
CREATE DATABASE phabricator_herald;
2+
3+
CREATE TABLE phabricator_herald.herald_action (
4+
id int unsigned not null auto_increment primary key,
5+
ruleID int unsigned not null,
6+
action varchar(255) not null,
7+
target text not null
8+
);
9+
10+
CREATE TABLE phabricator_herald.herald_rule (
11+
id int unsigned not null auto_increment primary key,
12+
name varchar(255) not null,
13+
authorPHID varchar(64) binary not null,
14+
contentType varchar(255) not null,
15+
mustMatchAll bool not null,
16+
configVersion int unsigned not null default '1',
17+
dateCreated int unsigned not null,
18+
dateModified int unsigned not null,
19+
unique key (authorPHID, name)
20+
);
21+
22+
CREATE TABLE phabricator_herald.herald_condition (
23+
id int unsigned not null auto_increment primary key,
24+
ruleID int unsigned not null,
25+
fieldName varchar(255) not null,
26+
fieldCondition varchar(255) not null,
27+
value text not null
28+
);
29+
30+
CREATE TABLE phabricator_herald.herald_transcript (
31+
id int unsigned not null auto_increment primary key,
32+
phid varchar(64) binary not null,
33+
time int unsigned not null,
34+
host varchar(255) not null,
35+
psth varchar(255) not null,
36+
duration float not null,
37+
objectPHID varchar(64) binary not null,
38+
dryRun bool not null,
39+
objectTranscript longblob not null,
40+
ruleTranscripts longblob not null,
41+
conditionTranscripts longblob not null,
42+
applyTranscripts longblob not null,
43+
unique key (phid)
44+
);

src/applications/diffusion/controller/commit/DiffusionCommitController.php

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ public function processRequest() {
3030

3131
$repository = $drequest->getRepository();
3232
$commit = $drequest->loadCommit();
33+
34+
if (!$commit) {
35+
// TODO: Make more user-friendly.
36+
throw new Exception('This commit has not parsed yet.');
37+
}
38+
3339
$commit_data = $drequest->loadCommitData();
3440

3541
require_celerity_resource('diffusion-commit-view-css');
@@ -70,19 +76,38 @@ public function processRequest() {
7076

7177
$count = number_format(count($changes));
7278

73-
$change_panel = new AphrontPanelView();
74-
$change_panel->setHeader("Changes ({$count})");
75-
$change_panel->appendChild($change_table);
76-
77-
$content[] = $change_panel;
78-
79-
80-
$change_list =
81-
'<div style="margin: 2em; color: #666; padding: 1em; background: #eee;">'.
82-
'(list of changes goes here)'.
83-
'</div>';
84-
85-
$content[] = $change_list;
79+
$bad_commit = null;
80+
if ($count == 0) {
81+
$bad_commit = queryfx_one(
82+
id(new PhabricatorRepository())->establishConnection('r'),
83+
'SELECT * FROM %T WHERE fullCommitName = %s',
84+
PhabricatorRepository::TABLE_BADCOMMIT,
85+
'r'.$repository->getCallsign().$commit->getCommitIdentifier());
86+
}
87+
88+
if ($bad_commit) {
89+
$error_panel = new AphrontErrorView();
90+
$error_panel->setWidth(AphrontErrorView::WIDTH_WIDE);
91+
$error_panel->setTitle('Bad Commit');
92+
$error_panel->appendChild(
93+
phutil_escape_html($bad_commit['description']));
94+
95+
$content[] = $error_panel;
96+
} else {
97+
$change_panel = new AphrontPanelView();
98+
$change_panel->setHeader("Changes ({$count})");
99+
$change_panel->appendChild($change_table);
100+
101+
$content[] = $change_panel;
102+
103+
$change_list =
104+
'<div style="margin: 2em; color: #666; padding: 1em;
105+
background: #eee;">'.
106+
'(list of changes goes here)'.
107+
'</div>';
108+
109+
$content[] = $change_list;
110+
}
86111

87112
return $this->buildStandardPageResponse(
88113
$content,

src/applications/diffusion/controller/commit/__init__.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99
phutil_require_module('phabricator', 'applications/diffusion/controller/base');
1010
phutil_require_module('phabricator', 'applications/diffusion/query/pathchange/base');
1111
phutil_require_module('phabricator', 'applications/diffusion/view/commitchangetable');
12+
phutil_require_module('phabricator', 'applications/repository/storage/repository');
1213
phutil_require_module('phabricator', 'infrastructure/celerity/api');
14+
phutil_require_module('phabricator', 'storage/queryfx');
15+
phutil_require_module('phabricator', 'view/form/error');
1316
phutil_require_module('phabricator', 'view/layout/panel');
1417

1518
phutil_require_module('phutil', 'markup');
19+
phutil_require_module('phutil', 'utils');
1620

1721

1822
phutil_require_source('DiffusionCommitController.php');

src/applications/repository/storage/repository/PhabricatorRepository.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class PhabricatorRepository extends PhabricatorRepositoryDAO {
2222
const TABLE_PATHCHANGE = 'repository_pathchange';
2323
const TABLE_FILESYSTEM = 'repository_filesystem';
2424
const TABLE_SUMMARY = 'repository_summary';
25+
const TABLE_BADCOMMIT = 'repository_badcommit';
2526

2627
protected $phid;
2728
protected $name;

src/applications/repository/worker/base/PhabricatorRepositoryCommitParserWorker.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,16 @@ protected function getSVNLogXMLObject($uri, $revision) {
8484
return new SimpleXMLElement($xml);
8585
}
8686

87+
protected function isBadCommit($full_commit_name) {
88+
$repository = new PhabricatorRepository();
89+
90+
$bad_commit = queryfx_one(
91+
$repository->establishConnection('w'),
92+
'SELECT * FROM %T WHERE fullCommitName = %s',
93+
PhabricatorRepository::TABLE_BADCOMMIT,
94+
$full_commit_name);
95+
96+
return (bool)$bad_commit;
97+
}
98+
8799
}

src/applications/repository/worker/base/__init__.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
phutil_require_module('phabricator', 'applications/repository/storage/commit');
1010
phutil_require_module('phabricator', 'applications/repository/storage/repository');
1111
phutil_require_module('phabricator', 'infrastructure/daemon/workers/worker');
12+
phutil_require_module('phabricator', 'storage/queryfx');
1213

1314
phutil_require_module('phutil', 'future/exec');
1415
phutil_require_module('phutil', 'parser/uri');

src/applications/repository/worker/commitchangeparser/git/PhabricatorRepositoryGitCommitChangeParserWorker.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ protected function parseCommit(
2323
PhabricatorRepository $repository,
2424
PhabricatorRepositoryCommit $commit) {
2525

26+
$full_name = 'r'.$repository->getCallsign().$commit->getCommitIdentifier();
27+
echo "Parsing {$full_name}...\n";
28+
if ($this->isBadCommit($full_name)) {
29+
echo "This commit is marked bad!\n";
30+
return;
31+
}
32+
2633
$local_path = $repository->getDetail('local-path');
2734

2835
list($raw) = execx(

src/applications/repository/worker/commitchangeparser/svn/PhabricatorRepositorySvnCommitChangeParserWorker.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ protected function parseCommit(
4444
$svn_commit = $commit->getCommitIdentifier();
4545

4646
$callsign = $repository->getCallsign();
47-
echo "Parsing r{$callsign}{$svn_commit}...\n";
47+
$full_name = 'r'.$callsign.$svn_commit;
48+
echo "Parsing {$full_name}...\n";
49+
50+
if ($this->isBadCommit($full_name)) {
51+
echo "This commit is marked bad!\n";
52+
return;
53+
}
4854

4955
// Pull the top-level path changes out of "svn log". This is pretty
5056
// straightforward; just parse the XML log.

0 commit comments

Comments
 (0)