如何通过API密钥认证的Phabricator API编程分配用户审核Diff?
Alright, let's break down exactly how to assign a Diff's review to a specific user using Phabricator's Conduit API—assuming you already have a valid API key set up for authentication.
Step 1: Know the Core API Endpoint
Phabricator manages Diffs under Revisions, so we'll use the differential.revision.edit endpoint. This lets us modify revision properties, including adding or updating reviewers.
Step 2: Gather Required Identifiers
Before making the request, you need two key pieces of info:
- The Revision ID (looks like
D1234) or its PHID for the Diff you want to update. - The PHID of the target user (e.g.,
PHID-USER-abc123). If you don't have this, you can fetch it via theuser.queryAPI by passing the username:curl -X POST https://your-phab-instance.com/api/user.query \ -d api.token=YOUR_API_KEY \ -d constraints[usernames][0]=target_username
Step 3: Construct the API Request
Send a POST request to the differential.revision.edit endpoint with the following JSON payload. Here's a curl example you can adapt:
curl -X POST https://your-phab-instance.com/api/differential.revision.edit \ -H "Content-Type: application/json" \ -d '{ "api.token": "YOUR_API_KEY", "objectIdentifier": "D1234", # Replace with your Revision ID/PHID "transactions": [ { "type": "reviewers.add", "value": ["PHID-USER-abc123"] # Replace with target user PHID } ] }'
Key Transaction Details:
- Use
reviewers.addto append the user to the existing list of reviewers. - If you want to replace all existing reviewers with this user, swap
reviewers.addforreviewers.set. - You can add multiple reviewers at once by including more PHIDs in the
valuearray (e.g.,["PHID-USER-abc123", "PHID-USER-def456"]).
Step 4: Verify the Assignment Worked
To confirm the change took effect, query the revision details using differential.revision.query:
curl -X POST https://your-phab-instance.com/api/differential.revision.query \ -d api.token=YOUR_API_KEY \ -d constraints[ids][0]=1234 # Match the numeric part of your Revision ID (D1234 → 1234)
Check the reviewers field in the response to see if the target user is listed.
Critical Permissions Check
Make sure your API key is linked to a user account that has:
- Permission to edit the target Revision.
- Permission to add or modify reviewers for that Revision.
内容的提问来源于stack exchange,提问作者Will

