问题
Our team has recently started experimenting with using Phabricator for code reviews.
Apart from Phabricator, we have a test-system that automatically builds and tests any code pushed to a specific branch on our main git repo. Is there any way to get arc diff
to automatically push the diff to that specific branch? The tests usually take a couple of hours, and I would prefer if it would be possible for people to review the code while it is being tested. Could it somehow be integrated as a unit test that does not have to complete before the diff is sent fo review?
回答1:
The purpose of arc diff
is that it will allow tests/Code Review to be performed without landing the code on a branch. We do this here through Herald rules, Harbormaster build plans, and Jenkins.
When a diff is created/updated, the Herald rule that is watching that Repo triggers the Harbormaster build plan that triggers Jenkins via an HTTP post request. I will try to detail out the basics but, I recommend looking at some additional materials as you build this process, if you choose to go this route.
PLEASE NOTE - Harbormaster is listed as a "Prototype". Meaning, there is limited support for it. But, aside from writing your own custom code, there is no other way to do what I'm suggesting here.
I hope to have enough here to get you started. Crafting to your specific needs will require much more detail from your side. This is what we do, and it works well for us. I hope it works well for you.
Setting up the test Job
The Test Job will have to be parameterized so you can pass your Diff and build ID in as a parameter.
Inside your test, you would do something like this to pull code in from the diff:
#!/bin/bash
# Clean the branch
git fetch --all
git checkout master
git reset --hard origin/master
git pull
# Delete the arcpatch branch (ignoring error if the branch doesn't exist)
git branch -D arcpatch-D$DIFF || true
# Apply the patch
arc patch D$DIFF
# Update dependencies
git submodule update
composer install
Then trigger your usual tests. After the tests, you will need some code like this to see update Phabricator with the build results:
#!/bin/bash
# Let Phabricator know if the build succeeded
if [ -n "$PHID" ]; then
export PATH=$PATH:~/bin/arcanist/bin
if [ {{{Code to determine Failure}}} ]; then
jsonResult="{\"buildTargetPHID\":\"$PHID\",\"type\":\"fail\"}";
else
jsonResult="{\"buildTargetPHID\":\"$PHID\",\"type\":\"pass\"}";
fi
echo $jsonResult | arc call-conduit harbormaster.sendmessage;
fi
Review the Code
Meanwhile, developers can reference that diff (http://{Phabricator.url}/D####), review the code, and can even run any tests by following a similar process as the test job is doing above.
Herald Rule
The Herald Rule will trigger on Differential Revisions. It will be looking for whatever indicates a change you are wanting to test (usually anything in a particular repo) and will Run the build plan (please see additional references on how to create a build plan that links to Jenkins if that is what you use).
Additional references:
http://www.guywarner.com/2014/05/integrating-jenkins-and-phabricator.html http://www.guywarner.com/2014/06/part-2-integrating-phabricator-and.html
回答2:
Another option is to configure Diffusion to observe your git repository and create a "staging" area. This will cause arc diff
to automatically push to the configured staging remote w/ tags like phabricator/diff/123
.
See https://secure.phabricator.com/book/phabricator/article/harbormaster/#change-handoff for more information
来源:https://stackoverflow.com/questions/29173784/is-there-any-way-to-get-phabricator-to-push-diffs-to-a-repository