1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-25 16:22:43 +01:00

Expose commit information via conduit instead of user information

Summary:
After D4825, this information is often available to us in a safe way. Provide it explictly.

This removes or reduces functionality in some cases, but I think we can plug those holes with Conpherence addresses and/or explicit user acknowledgement/config.

Test Plan: Patched a commit with `arc patch` and got the original address out.

Reviewers: btrahan, edward, vrana

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D4828
This commit is contained in:
epriestley 2013-02-05 20:10:57 -08:00
parent 574bc3ba31
commit 24ced7e7bd
4 changed files with 8 additions and 80 deletions

View file

@ -1015,17 +1015,6 @@ return array(
// interact with the revisions.
'differential.anonymous-access' => false,
// If you set this to true, revision author email address information will
// be exposed in Conduit. This is useful for Arcanist.
//
// For example, consider the "arc patch DX" workflow which needs to ask
// Differential for the revision DX. This data often should contain
// the author's email address, eg "George Washington
// <gwashinton@example.com>" when DX is a git or mercurial revision. If this
// option is false, Differential defaults to the best it can, something like
// "George Washington" or "gwashington".
'differential.expose-emails-prudently' => false,
// List of file regexps that should be treated as if they are generated by
// an automatic process, and thus get hidden by default in differential.
'differential.generated-paths' => array(

View file

@ -72,7 +72,6 @@ final class ConduitAPI_differential_getdiff_Method extends ConduitAPIMethod {
$project_name = null;
}
$basic_dict['projectName'] = $project_name;
$basic_dict['author'] = $diff->loadAuthorInformation();
return $basic_dict;
}

View file

@ -127,28 +127,6 @@ final class PhabricatorDifferentialConfigOptions
"If you set this to true, users won't need to login to view ".
"Differential revisions. Anonymous users will have read-only ".
"access and won't be able to interact with the revisions.")),
$this->newOption('differential.expose-emails-prudently', 'bool', false)
->setBoolOptions(
array(
pht("Expose revision author email address via Conduit"),
pht("Don't expose revision author email address via Conduit"),
))
->setSummary(
pht(
"Determines whether or not the author's email address should be ".
"exposed via Conduit."))
->setDescription(
pht(
"If you set this to true, revision author email address ".
"information will be exposed in Conduit. This is useful for ".
"Arcanist.\n\n".
"For example, consider the 'arc patch DX' workflow which needs ".
"to ask Differential for the revision DX. This data often should ".
"contain the author's email address, eg 'George Washington ".
"<gwashinton@example.com>' when DX is a git or mercurial ".
"revision. If this option is false, Differential defaults to the ".
"best it can, something like 'George Washington' or ".
"'gwashington'.")),
$this->newOption('differential.generated-paths', 'list<string>', array())
->setSummary(pht("File regexps to treat as automatically generated."))
->setDescription(

View file

@ -240,55 +240,17 @@ final class DifferentialDiff extends DifferentialDAO {
$this->getID());
foreach ($properties as $property) {
$dict['properties'][$property->getName()] = $property->getData();
if ($property->getName() == 'local:commits') {
foreach ($property->getData() as $commit) {
$dict['authorName'] = $commit['author'];
$dict['authorEmail'] = $commit['authorEmail'];
break;
}
}
}
return $dict;
}
/**
* Figures out the right author information for a given diff based on the
* repository and Phabricator configuration settings.
*
* Git is particularly finicky as it requires author information to be in
* the format "George Washington <gwashington@example.com>" to
* consistently work. If the Phabricator instance isn't configured to
* expose emails prudently, then we are unable to get any author information
* for git.
*/
public function loadAuthorInformation() {
$author = id(new PhabricatorUser())
->loadOneWhere('phid = %s', $this->getAuthorPHID());
$use_emails =
PhabricatorEnv::getEnvConfig('differential.expose-emails-prudently');
switch ($this->getSourceControlSystem()) {
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
if (!$use_emails) {
$author_info = '';
} else {
$author_info = $this->getFullAuthorInfo($author);
}
break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
if (!$use_emails) {
$author_info = $author->getUsername();
} else {
$author_info = $this->getFullAuthorInfo($author);
}
break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
default:
$author_info = $author->getUsername();
break;
}
return $author_info;
}
private function getFullAuthorInfo(PhabricatorUser $author) {
return sprintf('%s <%s>',
$author->getRealName(),
$author->loadPrimaryEmailAddress());
}
}