mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 00:42:41 +01: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:
parent
2f5c6541fc
commit
632cafec88
6 changed files with 76 additions and 0 deletions
|
@ -54,4 +54,28 @@ final class DifferentialBuildableEngine
|
||||||
$this->applyTransactions(array($xaction));
|
$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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,4 +34,10 @@ final class DiffusionBuildableEngine
|
||||||
$this->applyTransactions(array($xaction));
|
$this->applyTransactions(array($xaction));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getAuthorIdentity() {
|
||||||
|
return $this->getObject()
|
||||||
|
->loadIdentities($this->getViewer())
|
||||||
|
->getAuthorIdentity();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,5 +101,8 @@ abstract class HarbormasterBuildableEngine
|
||||||
$xactions);
|
$xactions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getAuthorIdentity() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
$json_data = phutil_json_encode($data_structure);
|
||||||
|
|
||||||
$credential_phid = $this->getSetting('token');
|
$credential_phid = $this->getSetting('token');
|
||||||
|
|
|
@ -200,6 +200,8 @@ final class PhabricatorRepositoryCommit
|
||||||
|
|
||||||
$this->authorIdentity = $author;
|
$this->authorIdentity = $author;
|
||||||
$this->committerIdentity = $committer;
|
$this->committerIdentity = $committer;
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAuthorIdentity() {
|
public function getAuthorIdentity() {
|
||||||
|
@ -485,6 +487,23 @@ final class PhabricatorRepositoryCommit
|
||||||
return null;
|
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() {
|
public function hasCommitterIdentity() {
|
||||||
return ($this->getCommitterIdentity() !== null);
|
return ($this->getCommitterIdentity() !== null);
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,6 +65,16 @@ final class PhabricatorRepositoryIdentity
|
||||||
$this->getIdentityNameEncoding());
|
$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() {
|
public function getIdentityShortName() {
|
||||||
// TODO
|
// TODO
|
||||||
return $this->getIdentityName();
|
return $this->getIdentityName();
|
||||||
|
|
Loading…
Reference in a new issue