2011-03-22 21:22:40 +01:00
|
|
|
<?php
|
|
|
|
|
2012-03-14 00:21:04 +01:00
|
|
|
final class HeraldActionConfig {
|
2011-03-22 21:22:40 +01:00
|
|
|
|
|
|
|
const ACTION_ADD_CC = 'addcc';
|
|
|
|
const ACTION_REMOVE_CC = 'remcc';
|
|
|
|
const ACTION_EMAIL = 'email';
|
|
|
|
const ACTION_NOTHING = 'nothing';
|
Allow Herald to trigger audits for users or projects
Summary:
Allows you to write a commit rule that triggers an audit by a user (personal
rules) or a project (global rules).
Mostly this is trying to make auditing more lightweight and accessible in
environments where setting up Owners packages doesn't make sense.
For instance, Disqus wants a rule like "trigger an audit for everything that
didn't have a Differential revision". While not necessarily scalable, this is a
perfectly reasonable rule for a small company, but a lot of work to implement
with Owners (and you'll get a lot of collateral damage if you don't make every
committer a project owner).
Instead, they can create a project called 'Unreviewed Commits' and write a rule
like:
- When: Differential revision does not exist
- Action: Trigger an Audit for project: "Unreviewed Commits"
Then whoever cares can join that project and they'll see those audits in their
queue, and when they approve/raise on commits their actions will affect the
project audit.
Similarly, if I want to look at all commits that match some other rule (say,
XSS) but only want to do it like once a month, I can just set up an audit rule
and go through the queue when I feel like it.
NOTE: This abuses the 'packagePHID' field to also store user and project PHIDs.
Through the magic of handles, this (apparently) works fine for now; I'll do a
big schema patch soon but have several other edits I want to make at the same
time.
Also:
- Adds an "active" fiew for /audit/, eventually this will be like the
Differential "active" view (stuff that is relevant to you right now).
- On commits, highlight triggered audits you are responsible for.
Test Plan: Added personal and global audit triggers to Herald, reparsed some
commits with --herald, got audits. Browsed all audit interfaces to make sure
nothing exploded. Viewed a commit where I was responsible for only some audits.
Performed audits and made sure the triggers I am supposed to be responsible for
updated properly.
Reviewers: btrahan, jungejason
Reviewed By: jungejason
CC: aran, epriestley
Maniphest Tasks: T904
Differential Revision: https://secure.phabricator.com/D1690
2012-02-27 18:36:30 +01:00
|
|
|
const ACTION_AUDIT = 'audit';
|
2012-03-30 22:51:54 +02:00
|
|
|
const ACTION_FLAG = 'flag';
|
2011-03-22 21:22:40 +01:00
|
|
|
|
2012-01-14 00:24:56 +01:00
|
|
|
public static function getActionMessageMapForRuleType($rule_type) {
|
2012-03-30 22:51:54 +02:00
|
|
|
$generic_mappings = array(
|
2013-05-20 17:24:07 +02:00
|
|
|
self::ACTION_NOTHING => pht('Do nothing'),
|
|
|
|
self::ACTION_ADD_CC => pht('Add emails to CC'),
|
|
|
|
self::ACTION_REMOVE_CC => pht('Remove emails from CC'),
|
|
|
|
self::ACTION_EMAIL => pht('Send an email to'),
|
|
|
|
self::ACTION_AUDIT => pht('Trigger an Audit'),
|
|
|
|
self::ACTION_FLAG => pht('Mark with flag'),
|
2012-03-30 22:51:54 +02:00
|
|
|
);
|
2012-01-14 00:24:56 +01:00
|
|
|
|
|
|
|
switch ($rule_type) {
|
|
|
|
case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL:
|
2012-03-30 22:51:54 +02:00
|
|
|
$specific_mappings = array(
|
2013-05-20 17:24:07 +02:00
|
|
|
self::ACTION_AUDIT => pht('Trigger an Audit for project'),
|
2012-03-30 22:51:54 +02:00
|
|
|
);
|
2012-01-14 00:24:56 +01:00
|
|
|
break;
|
|
|
|
case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL:
|
2012-03-30 22:51:54 +02:00
|
|
|
$specific_mappings = array(
|
2013-05-20 17:24:07 +02:00
|
|
|
self::ACTION_ADD_CC => pht('CC me'),
|
|
|
|
self::ACTION_REMOVE_CC => pht('Remove me from CC'),
|
|
|
|
self::ACTION_EMAIL => pht('Email me'),
|
|
|
|
self::ACTION_AUDIT => pht('Trigger an Audit by me'),
|
2012-03-30 22:51:54 +02:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
case null:
|
|
|
|
$specific_mappings = array();
|
|
|
|
// Use generic mappings, used on transcript.
|
2012-01-14 00:24:56 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new Exception("Unknown rule type '${rule_type}'");
|
|
|
|
}
|
2012-03-30 22:51:54 +02:00
|
|
|
return $specific_mappings + $generic_mappings;
|
2011-03-22 21:22:40 +01:00
|
|
|
}
|
|
|
|
|
2012-01-14 00:24:56 +01:00
|
|
|
public static function getActionMessageMap($content_type,
|
|
|
|
$rule_type) {
|
|
|
|
$map = self::getActionMessageMapForRuleType($rule_type);
|
|
|
|
switch ($content_type) {
|
2011-03-22 21:22:40 +01:00
|
|
|
case HeraldContentTypeConfig::CONTENT_TYPE_DIFFERENTIAL:
|
|
|
|
return array_select_keys(
|
|
|
|
$map,
|
|
|
|
array(
|
|
|
|
self::ACTION_ADD_CC,
|
|
|
|
self::ACTION_REMOVE_CC,
|
2011-05-28 00:52:26 +02:00
|
|
|
self::ACTION_EMAIL,
|
2012-03-30 22:51:54 +02:00
|
|
|
self::ACTION_FLAG,
|
2011-03-22 21:22:40 +01:00
|
|
|
self::ACTION_NOTHING,
|
|
|
|
));
|
|
|
|
case HeraldContentTypeConfig::CONTENT_TYPE_COMMIT:
|
|
|
|
return array_select_keys(
|
|
|
|
$map,
|
|
|
|
array(
|
|
|
|
self::ACTION_EMAIL,
|
Allow Herald to trigger audits for users or projects
Summary:
Allows you to write a commit rule that triggers an audit by a user (personal
rules) or a project (global rules).
Mostly this is trying to make auditing more lightweight and accessible in
environments where setting up Owners packages doesn't make sense.
For instance, Disqus wants a rule like "trigger an audit for everything that
didn't have a Differential revision". While not necessarily scalable, this is a
perfectly reasonable rule for a small company, but a lot of work to implement
with Owners (and you'll get a lot of collateral damage if you don't make every
committer a project owner).
Instead, they can create a project called 'Unreviewed Commits' and write a rule
like:
- When: Differential revision does not exist
- Action: Trigger an Audit for project: "Unreviewed Commits"
Then whoever cares can join that project and they'll see those audits in their
queue, and when they approve/raise on commits their actions will affect the
project audit.
Similarly, if I want to look at all commits that match some other rule (say,
XSS) but only want to do it like once a month, I can just set up an audit rule
and go through the queue when I feel like it.
NOTE: This abuses the 'packagePHID' field to also store user and project PHIDs.
Through the magic of handles, this (apparently) works fine for now; I'll do a
big schema patch soon but have several other edits I want to make at the same
time.
Also:
- Adds an "active" fiew for /audit/, eventually this will be like the
Differential "active" view (stuff that is relevant to you right now).
- On commits, highlight triggered audits you are responsible for.
Test Plan: Added personal and global audit triggers to Herald, reparsed some
commits with --herald, got audits. Browsed all audit interfaces to make sure
nothing exploded. Viewed a commit where I was responsible for only some audits.
Performed audits and made sure the triggers I am supposed to be responsible for
updated properly.
Reviewers: btrahan, jungejason
Reviewed By: jungejason
CC: aran, epriestley
Maniphest Tasks: T904
Differential Revision: https://secure.phabricator.com/D1690
2012-02-27 18:36:30 +01:00
|
|
|
self::ACTION_AUDIT,
|
2012-03-30 22:51:54 +02:00
|
|
|
self::ACTION_FLAG,
|
2011-03-22 21:22:40 +01:00
|
|
|
self::ACTION_NOTHING,
|
|
|
|
));
|
|
|
|
case HeraldContentTypeConfig::CONTENT_TYPE_MERGE:
|
|
|
|
return array_select_keys(
|
|
|
|
$map,
|
|
|
|
array(
|
|
|
|
self::ACTION_EMAIL,
|
|
|
|
self::ACTION_NOTHING,
|
|
|
|
));
|
|
|
|
case HeraldContentTypeConfig::CONTENT_TYPE_OWNERS:
|
|
|
|
return array_select_keys(
|
|
|
|
$map,
|
|
|
|
array(
|
|
|
|
self::ACTION_EMAIL,
|
|
|
|
self::ACTION_NOTHING,
|
|
|
|
));
|
|
|
|
default:
|
2012-06-12 01:22:08 +02:00
|
|
|
throw new Exception("Unknown content type '{$content_type}'.");
|
2011-03-22 21:22:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-14 00:24:56 +01:00
|
|
|
/**
|
|
|
|
* Create a HeraldAction to save from data.
|
|
|
|
*
|
|
|
|
* $data is of the form:
|
|
|
|
* array(
|
|
|
|
* 0 => <action type>
|
|
|
|
* 1 => array(<targets>)
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public static function willSaveAction($rule_type,
|
|
|
|
$author_phid,
|
|
|
|
$data) {
|
|
|
|
$obj = new HeraldAction();
|
|
|
|
$obj->setAction($data[0]);
|
|
|
|
|
|
|
|
// for personal rule types, set the target to be the owner of the rule
|
|
|
|
if ($rule_type == HeraldRuleTypeConfig::RULE_TYPE_PERSONAL) {
|
|
|
|
switch ($obj->getAction()) {
|
|
|
|
case HeraldActionConfig::ACTION_EMAIL:
|
|
|
|
case HeraldActionConfig::ACTION_ADD_CC:
|
|
|
|
case HeraldActionConfig::ACTION_REMOVE_CC:
|
Allow Herald to trigger audits for users or projects
Summary:
Allows you to write a commit rule that triggers an audit by a user (personal
rules) or a project (global rules).
Mostly this is trying to make auditing more lightweight and accessible in
environments where setting up Owners packages doesn't make sense.
For instance, Disqus wants a rule like "trigger an audit for everything that
didn't have a Differential revision". While not necessarily scalable, this is a
perfectly reasonable rule for a small company, but a lot of work to implement
with Owners (and you'll get a lot of collateral damage if you don't make every
committer a project owner).
Instead, they can create a project called 'Unreviewed Commits' and write a rule
like:
- When: Differential revision does not exist
- Action: Trigger an Audit for project: "Unreviewed Commits"
Then whoever cares can join that project and they'll see those audits in their
queue, and when they approve/raise on commits their actions will affect the
project audit.
Similarly, if I want to look at all commits that match some other rule (say,
XSS) but only want to do it like once a month, I can just set up an audit rule
and go through the queue when I feel like it.
NOTE: This abuses the 'packagePHID' field to also store user and project PHIDs.
Through the magic of handles, this (apparently) works fine for now; I'll do a
big schema patch soon but have several other edits I want to make at the same
time.
Also:
- Adds an "active" fiew for /audit/, eventually this will be like the
Differential "active" view (stuff that is relevant to you right now).
- On commits, highlight triggered audits you are responsible for.
Test Plan: Added personal and global audit triggers to Herald, reparsed some
commits with --herald, got audits. Browsed all audit interfaces to make sure
nothing exploded. Viewed a commit where I was responsible for only some audits.
Performed audits and made sure the triggers I am supposed to be responsible for
updated properly.
Reviewers: btrahan, jungejason
Reviewed By: jungejason
CC: aran, epriestley
Maniphest Tasks: T904
Differential Revision: https://secure.phabricator.com/D1690
2012-02-27 18:36:30 +01:00
|
|
|
case HeraldActionConfig::ACTION_AUDIT:
|
2012-01-14 00:24:56 +01:00
|
|
|
$data[1] = array($author_phid => $author_phid);
|
|
|
|
break;
|
2012-03-30 22:51:54 +02:00
|
|
|
case HeraldActionConfig::ACTION_FLAG:
|
|
|
|
// Make sure flag color is valid; set to blue if not.
|
|
|
|
$color_map = PhabricatorFlagColor::getColorNameMap();
|
|
|
|
if (empty($color_map[$data[1]])) {
|
|
|
|
$data[1] = PhabricatorFlagColor::COLOR_BLUE;
|
|
|
|
}
|
|
|
|
break;
|
2012-01-14 00:24:56 +01:00
|
|
|
case HeraldActionConfig::ACTION_NOTHING:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new Exception('Unrecognized action type: ' .
|
|
|
|
$obj->getAction());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_array($data[1])) {
|
|
|
|
$obj->setTarget(array_keys($data[1]));
|
|
|
|
} else {
|
|
|
|
$obj->setTarget($data[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $obj;
|
|
|
|
}
|
|
|
|
|
2011-03-22 21:22:40 +01:00
|
|
|
}
|