programmatically create phabricator diff request without any repo - phabricator

I am trying to simulate creating diff request without actually creating the repo, diff and doing arc diff.
I want to use the
https://secure.phabricator.com/conduit/method/differential.createrawdiff/
or the createDiff command. But I am not sure what should the json be ?
How is the diff request sent over ? How do I fake create that to be used with the curl request ?
Any insights and help is greatly appreciated ?
Thanks so much

This was the json I used:
'{
"diff": "diff --git a/scripts/deploy/restart_apache b/scripts/deploy/restart_apache\nindex 510a7f9..d29177c 100755\n--- a/scripts/deploy/restart_apache\n+++ b/scripts/deploy/restart_apache\n## -59,7 +59,7 ## do\n # Set variables for the alpha context.\n webServerBaseName='\''alpha-w'\''\n webServerSuffix='\'''\''\n- numWebServers=1\n+ numWebServers=2\n checkPort=80\n ;;\n \"beta\")"
}'
You will, however, need to use Arcanist. I do not believe there is a way to use the API without using Arcanist. Yo don't need to use arc diff but you will still need Arcanist. The command you would use through Arcanist is this:
echo $json_string | arc call-conduit --conduit-uri https://secure.phabricator.com/ --conduit-token $conduit_token differential.createrawdiff

Related

expected at least 1 argument, got 0

I installed robot framework yesterday and trying to run a test file.Below is my test file, while i try to run the file using robot -d tests/Amazon.robot , i am getting a error as
[Error] Expected at least 1 argument,got 0.
can someone please help me.
You didn't specify where to look for tests and you are using -d incorrectly.
Most likely you need command robot tests/Amazon.robot
The problem looks like in the usage of the Sleep keyword - you want to pass the argument "3" to it, but did not put two or more spaces b/n them.
With problems like this, check the generated log.html file - the failure will be in the record for the specific keyword, helping you pinpoint which line is the error one.

View JSON file in Midnight Commander using jq

So there is that awesome tool for working with JSON data called jq.
And there is that awesome linux file manager called mc.
One day (today) I came around an idea to integrate these two, so I could easily preview JSON files in a pretty/formatted way using F3 keyboard shortcut when in Midnight Commander.
I opened MC extension file using Command → Edit extension file menu actions and then added following to such opened configuration file:
# json
regex/\.json$
View=%view{ascii} jq < %f
I thought it is straightforward, but unexpectedly it does not work: trying to view the JSON (F3) results in error popup with contents of jq's help page (the same as when you type jq by itself), so starting with: "jq - commandline JSON processr [version 1.5]..."
Can anybody tell me why this configuration is incorrect?
Two minutes after I submitted my question I've been revealed.
I thought that maybe jq does not produce standard output... It led me to this question: How to use jq in a shell pipeline? and so I have modified the extension file to look like:
# json
regex/\.json$
View=%view{ascii} jq '.' < %f
And now it works as expected, piping result of jq to the internal mc viewer.
Thank you, me ;)
You don't have to use redirection < here, you could use just a plain filename %f:
# json
regex/\.json$
View=%view{ascii} jq '.' %f
and as you mentioned you have to use a simple filter: .
For anyone wondering, why this no longer works. In version 4.8.29, MC switched from mc.ext to the new mc.ext.ini ini file, which has slightly different syntax. The new entry should look like this
[JSON]
Regex=\.json$
View=%view{ascii} jq '.' < %f
The [JSON] line is necessary.

Build web graph with wget

I'm using wget with -r (recursive) option, to crawl and download all the pages starting from a root.
For debugging purpose I'd like to output which page routed me to another one, for example: https://stackoverflow.com/ -> https://stackoverflow.com/questions
Is there such a way to do that?
Please note that I need explicitly use wget.
The best solution I found untill now is to use the --warc-file option, to export a warc archive of my crawl. This format also store the Referer.
Using a python library to read the output I wrote the following simple script, to export a csv with source/target columns:
import warc
f = warc.open("crawler.warc")
for record in f:
if record['WARC-Type'] != 'request':
continue
for line in record.payload:
if line.startswith("Referer:"):
print line.replace("Referer: ", "").strip('\n\r'), ",", record['WARC-Target-URI']

how to run arc diff in a script, without prompting for a message

Phabricator's arcanist command line tool allows you to add a "diff" for revision. This is useful because you can quickly generate a diff which your colleagues can review.
Normally, running arc diff master, for example, will prompt your for a diff message, a test plan, and some other information, and then create a diff on Phabricator.
However, I would like to run arc diff from a continuous integration server, therefore assuming yes to all questions and passing the message and test plan as an argument to the command. What I have now is:
arc diff master --allow-untracked
Still, it is assuming that it is being called from a human user, and asking for a message, which fails when called from a continuous integration server. How can skip the prompts?
I think what you are looking for is the --verbatim option.
Considering the changes are committed so that it has a commit message you can run a command like:
arc diff --verbatim --reviewers xxxx --uncommitted --allow-untracked
This implies you set the Test plan to optional, else you have to specify it as well.
Finally you can also read revision info from a file using --message-file.
Another approach would be:
Create a Diff (but not a rev) with arc diff --raw-command "git diff origin/master"
Read the result to get the diff Id
Use the createrevision conduit call as described here to create the revision:
https://secure.phabricator.com/conduit/method/differential.createrevision/
the best practice is:
You can prepare a template file like this. This file can be named msg.conf
${title}
Summary:
${summary_content}
修订人:
${reviewers}
订阅者:
RBA-DEV
Test Plan:
${test_plan}
and then you can generate some content you need to fill this template and then.
you can rum this command:
arc diff --create --allow-untracked --skip-binaries --message-file msg.conf origin/master

TeamCity Current Date variable in MMdd format

In TeamCity is there an easy way to get a variable for the current date in the format MMdd (eg 0811 for 8-Aug)?
My google-fu did not turn up an existing plugins. I looked into writing a plugin, but not having a jdk installed, that looks time consuming.
This is quite easy to do with a PowerShell build step (no plugin required) using the following source code:
echo "##teamcity[setParameter name='env.BUILD_START_TIME' value='$([DateTime]::Now)']"
or (for UTC):
echo "##teamcity[setParameter name='env.BUILD_START_TIME' value='$([DateTime]::UtcNow)']"
This uses TeamCity's Service Message feature that allows you to interact with the build engine at runtime e.g. set build parameters.
You can then reference this build parameter from other places in TeamCity using the syntax %env.BUILD_START_TIME%
The advantage of this approach is you don't need to use a plugin. The disadvantage is you need to introduce a build step.
For Unix based build agents I propose next custom script as one of build commands:
export current_build_date_format="+%%Y.%%m.%%d"
export current_build_date="$(date $current_build_date_format)"
echo "##teamcity[setParameter name='env.current_build_date' value='$current_build_date']"
You have to make double % sign to avoid interpretation for date executable command line argument FORMAT string (see %Y.%m.%d) as already existing TeamCity variable.
The Groovy Plugin for TeamCity provides build start date/time properties:
Provides build properties:
system.build.start.date / env.BUILD_START_DATE
system.build.start.time / env.BUILD_START_TIME
This blog post has installation / configuration instructions for the Groovy plugin, as well an example of customizing the date/time format.
You can also try Date Build Number plug-in. It povides additional var in build number format rather than build property.
Similar to the Date Build Number plugin mentioned in this answer, there exists a derived plugin called Formatted Date Parameter. It provides a customizable parameter build.formatted.timestamp that can be used out of the box in fields or other parameters. No need for a separate build step.
An old question, but for those looking for a solution now there is a system parameter available.
system.buildStartTime
You need to declare it in config (it's not available until runtime) in order to run. I set mine to value [Filled Automatically]
As you can guess, this time is set to the build start time, so that may not be ideal for some needs. But it's easy and reliable.
To add a dated folder to my build in TeamCity I added the following to my custom script. What had me stuck was the double % sign in the date string. D'oh
TARGET_DIR=/Users/admin/build/daily
TARGET=$(date "+%%Y-%%m-%%d")
if [ ! -d ${TARGET_DIR} ]; then
mkdir -vp ${TARGET_DIR}/
fi
mv -v build.dmg ${TARGET_DIR}/build_${TARGET}.dmg
If you only want to have one-line bash command in a build step, just use as below.
echo "##teamcity[setParameter name='build.timestamp' value='$(date +%%m%%d)']"
(double % symbol is for TeamCity own escape rule to use % character)
It will set a MMdd parameter value right after the execution during runtime so very useful to put at any build step. Then, you can retrieve a parameter value afterward.
Note that you should create build.timestamp parameter firstly to TeamCity project.
A step further, I made a simple bash script to have bash date format timestamp. This script will set timestamp to whatever bash supported datetime format and parameter name to TeamCity.
name="" # TeamCity parameter name
format="%Y-%m-%dT%H:%M:%S%z" # ISO8601 format by default
result="" # a TeamCity parameter value to be set
for ARGUMENT in "$#"
do
KEY=$(echo "$ARGUMENT" | cut -f1 -d=)
VALUE=$(echo "$ARGUMENT" | cut -f2 -d=)
case "$KEY" in
name) name=${VALUE} ;;
format) format=${VALUE} ;;
*)
esac
done
result=$(date "+$format")
echo "##teamcity[setParameter name='$name' value='$result']"
Below usage will set ISO8601 format timestamp to build.timestamp parameter.
./teamcity_datetime.sh name=build.timestamp
If you want to set only MMdd, the execution could be as below.
./teamcity_datetime.sh name=build.timestamp format="%%m%%d"

Resources