1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-19 16:58:48 +02:00

Pass commit authorship information to Buildkite

Summary:
Fixes T12251. Ref T13189. See PHI610. The difficulty here is that we don't want to disclose Phabricator account information to Buildkite. We're comfortable disclosing information from `git`, etc.

  - For commits, use the Identity to provide authorship information from Git.
  - For revisions, use the local commit information on the Diff to provide the Git/Mercurial/etc author of the HEAD commit.

Test Plan:
  - Built commits and revisions in Buildkite via Harbormaster.
  - I can't actually figure out how to see author information on the Buildkite side, but the values look sane when dumped locally.

Reviewers: amckinley

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13189, T12251

Differential Revision: https://secure.phabricator.com/D19614
This commit is contained in:
epriestley 2018-08-27 12:46:03 -07:00
parent 2f5c6541fc
commit 632cafec88
6 changed files with 76 additions and 0 deletions

View file

@ -54,4 +54,28 @@ final class DifferentialBuildableEngine
$this->applyTransactions(array($xaction));
}
public function getAuthorIdentity() {
$object = $this->getObject();
if ($object instanceof DifferentialRevision) {
$object = $object->loadActiveDiff();
}
$authorship = $object->getDiffAuthorshipDict();
if (!isset($authorship['authorName'])) {
return null;
}
$name = $authorship['authorName'];
$address = idx($authorship, 'authorEmail');
$full = id(new PhutilEmailAddress())
->setDisplayName($name)
->setAddress($address);
return id(new PhabricatorRepositoryIdentity())
->setIdentityName((string)$full)
->makeEphemeral();
}
}

View file

@ -34,4 +34,10 @@ final class DiffusionBuildableEngine
$this->applyTransactions(array($xaction));
}
public function getAuthorIdentity() {
return $this->getObject()
->loadIdentities($this->getViewer())
->getAuthorIdentity();
}
}

View file

@ -101,5 +101,8 @@ abstract class HarbormasterBuildableEngine
$xactions);
}
public function getAuthorIdentity() {
return null;
}
}

View file

@ -117,6 +117,20 @@ EOTEXT
),
);
$engine = HarbormasterBuildableEngine::newForObject(
$object,
$viewer);
$author_identity = $engine->getAuthorIdentity();
if ($author_identity) {
$data_structure += array(
'author' => array(
'name' => $author_identity->getIdentityDisplayName(),
'email' => $author_identity->getIdentityEmailAddress(),
),
);
}
$json_data = phutil_json_encode($data_structure);
$credential_phid = $this->getSetting('token');

View file

@ -200,6 +200,8 @@ final class PhabricatorRepositoryCommit
$this->authorIdentity = $author;
$this->committerIdentity = $committer;
return $this;
}
public function getAuthorIdentity() {
@ -485,6 +487,23 @@ final class PhabricatorRepositoryCommit
return null;
}
public function loadIdentities(PhabricatorUser $viewer) {
if ($this->authorIdentity !== self::ATTACHABLE) {
return $this;
}
$commit = id(new DiffusionCommitQuery())
->setViewer($viewer)
->withIDs(array($this->getID()))
->needIdentities(true)
->executeOne();
$author_identity = $commit->getAuthorIdentity();
$committer_identity = $commit->getCommitterIdentity();
return $this->attachIdentities($author_identity, $committer_identity);
}
public function hasCommitterIdentity() {
return ($this->getCommitterIdentity() !== null);
}

View file

@ -65,6 +65,16 @@ final class PhabricatorRepositoryIdentity
$this->getIdentityNameEncoding());
}
public function getIdentityEmailAddress() {
$address = new PhutilEmailAddress($this->getIdentityName());
return $address->getAddress();
}
public function getIdentityDisplayName() {
$address = new PhutilEmailAddress($this->getIdentityName());
return $address->getDisplayName();
}
public function getIdentityShortName() {
// TODO
return $this->getIdentityName();