Skip to main content

How to get the Phabricator's ticket No. by using the commit hash of `git`

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

  1. Get the commit-hash

    First of all, we get the difference of commits between the current branch and previous branch with git log command.

    git log --pretty=oneline $OLD_BRANCH..$NEW_BRANCH | awk '{print $1}'
    • $OLD_BRANCH: Previous release branch
    • $NEW_BRANCH: Current release branch
  2. Get the repository-ID

    Secondly, we need to get the repository's PHID to get the commit PHID. You can get it to use phid.lookup command.

    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
  3. Get the Phabricator's ID related the commit-hash

    Third, we can get the commit-PHID with diffusion.querycommits command.

    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 log command and it formatted list type
      • ex. ["hoge", "hogehoge"]
    • $PHABRICATOR_URL: Phabricator's URL
  4. 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.search API. This API is to get the information about selected types from selected source-PHID. types:commit.revision means differential-PHID

    echo '{"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
  5. 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.search command.

    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
  6. 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.task at 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
  7. Get the task ticket No. and title

    It is easy to get these with maniphest.search command.

    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

Finally

We are able to get a lot of information about Phabricator's API in the following link.

https://secure.phabricator.com/conduit/

Popular posts from this blog

How to mount the S3 bucket on to the Mac

How to mount the S3 bucket on to the Mac Description S3 is very powerful architecture. But it cannot use like normal directory. However, we have the solution to mount S3 on Mac PC. It's to use Storage Gateway . Archtecture Image ー ー ー Premise Storage Gateway: Requirements for Amazon EC2 instance types https://docs.aws.amazon.com/storagegateway/latest/userguide/Requirements.html#requirements-hardware-ec2 [Recommended for file gateway types] ・General-purpose instance family – m4 or m5 instance type. ・Compute-optimized instance family – c4 or c5 instance types. Choose the 2xlarge instance size or higher to meet the required RAM requirements. ・Memory-optimized instance family – r3 instance types. ・Storage-optimized instance family – i3 instance types. [Recommended for cached volumes and tape gateway type...

How to calculate the infinite product by SQL

How to calculate the infinite product by SQL Description I needed to calculate the infinite product in the creating ETL script. So I thought the solution to calculate it in the SQL. The following way is the solution I thought. Premise Use the standard SQL Code WITH sample_table AS ( SELECT 2 AS n1, 4 AS n2 UNION ALL SELECT 4 , 8 UNION ALL SELECT 10 , 20 UNION ALL SELECT 10 , 20 ) SELECT * FROM sample_table UNION ALL SELECT CAST ( EXP ( SUM ( LOG (n1))) AS INT64) AS inf_product1, CAST ( EXP ( SUM ( LOG (n2))) AS INT64) AS inf_product2 FROM sample_table The infinite product (∏) is able to convert to the total addition formula. ∏n1 ≒ e Σlog e n1 ∏n2 ≒ e Σlog e n2 Finally Actually, this calculated value is an approximation. So if you want an accurate number, this solution cannot use.