How to get the Phabricator's ticket No. by using the commit hash of git
Description
Sometimes, we would like to check that the release branch has only completed task's commit. For example, we must prove to be not including unapproved commit in the release branch at IT audit.
So, I write the operation to get the Phabricator's ticket No.
Operations
-
Get the
commit-hashFirst of all, we get the difference of commits between the current branch and previous branch with
git logcommand.git log --pretty=oneline $OLD_BRANCH..$NEW_BRANCH | awk '{print $1}'- $OLD_BRANCH: Previous release branch
- $NEW_BRANCH: Current release branch
-
Get the
repository-IDSecondly, we need to get the repository's PHID to get the commit PHID. You can get it to use
phid.lookupcommand.echo '{"names": ["$REPOSITORY_NAME"]}' | arc call-conduit --conduit-uri $PHABRICATOR_URL phid.lookup | jq .- $REPOSITORY_NAME: Repository name you want to get
- $PHABRICATOR_URL: Phabricator's URL
-
Get the Phabricator's ID related the commit-hash
Third, we can get the commit-PHID with
diffusion.querycommitscommand.echo '{"repositoryPHID": "$REPOSITORY_PHID","names": $COMMIT_LIST}' | arc call-conduit --conduit-uri $PHABRICATOR_URL diffusion.querycommits | jq -r ".response.data[].phid"- $REPOSITORY_PHID: Phabricator's PHID to be got with Operation No. 2
- $COMMIT_LIST: Hash to be got with
git logcommand and it formatted list type- ex. ["hoge", "hogehoge"]
- $PHABRICATOR_URL: Phabricator's URL
-
Get the Phabricator's ID related the commit-PHID (named
Differential-PHID)It is difficult to understand how to get the Differential-PHID with Commit-PHID. Because it is not able to get with diffusion API and differential API. So, we use
edge.searchAPI. This API is to get the information about selected types from selected source-PHID. types:commit.revisionmeans differential-PHIDecho '{"types": ["commit.revision"], "sourcePHIDs": $COMMIT_PHID_LIST}' | arc call-conduit --conduit-uri $PHABRICATOR_URL edge.search | jq -r ".response.data[].destinationPHID"- $COMMIT_PHID_LIST: Commit-PHID to be got Operation No. 3 and it formatted list type
- ex. ["PHID-CMIT-hoge", "PHID-CMIT-hogehoge"]
- $PHABRICATOR_URL: Phabricator's URL
- $COMMIT_PHID_LIST: Commit-PHID to be got Operation No. 3 and it formatted list type
-
Get the differential ticket No. and title
It is easy to get these if we have the differential-PHID. We have already it. So after, we can get it easy with
differential.revision.searchcommand.echo '{"constraints": {"phids": $DIFF_PHID_LIST}}' | arc call-conduit --conduit-uri $PHABRICATOR_URL differential.revision.search | jq -rc '.response.data[] | {"id": .id, "title": .fields.title}'- $DIFF_PHID_LIST: Differential-PHID to be got Operation No. 4 and it formatted list type
- ex. ["PHID-DREV-hoge", "PHID-DREV-hogehoge"]
- $PHABRICATOR_URL: Phabricator's URL
- $DIFF_PHID_LIST: Differential-PHID to be got Operation No. 4 and it formatted list type
-
Get the Phabricator's ID related the Differential-PHID (named
Task-PHID)We can get the Task-PHID with the same command as operation No.4. At this time, we set
revision.taskat types.echo '{"types": ["revision.task"], "sourcePHIDs": $DIFF_PHID_LIST}' | arc call-conduit --conduit-uri $PHABRICATOR_URL edge.search | jq -r ".response.data[].destinationPHID"- $DIFF_PHID_LIST: Differential-PHID to be got Operation No. 4 and it formatted list type
- ex. ["PHID-DREV-hoge", "PHID-DREV-hogehoge"]
- $PHABRICATOR_URL: Phabricator's URL
- $DIFF_PHID_LIST: Differential-PHID to be got Operation No. 4 and it formatted list type
-
Get the task ticket No. and title
It is easy to get these with
maniphest.searchcommand.echo '{"constraints": {"phids": $TASK_PHID_LIST}}' | arc call-conduit --conduit-uri $PHABRICATOR_URL maniphest.search | jq -rc '.response.data[] | {"id": .id, "title": .fields.name}'- $TASK_PHID_LIST: Task-PHID to be got Operation No. 6 and it formatted list type
- ex. ["PHID-TASK-hoge", "PHID-TASK-hogehoge"]
- $PHABRICATOR_URL: Phabricator's URL
- $TASK_PHID_LIST: Task-PHID to be got Operation No. 6 and it formatted list type
Finally
We are able to get a lot of information about Phabricator's API in the following link.