Page MenuHomePhabricator
Paste P2032

Creating diff from python using Conduit
ActivePublic

Authored by cspeckmim on Mar 24 2017, 2:11 PM.
Tags
None
Referenced Files
F4268334: Creating diff from python using Conduit
Mar 24 2017, 2:11 PM
F4268333: Creating diff from python using Conduit
Mar 24 2017, 2:11 PM
Subscribers
None
# Create a raw diff in Phabricator
post_data = {
'api.token': phab_api_token,
'diff': diff,
'repositoryPHID': respository_phid
}
try:
diff_phid = execute_conduit_api("differential.createrawdiff", post_data)["result"]["phid"]
ui.debug("STRINGS: Created diff of properties changes, PHID is %s" % diff_phid)
except Exception as err:
ui.warn("STRINGS: Failed to create diff of properties changes: %s" % err)
return True
def execute_conduit_api(api_method, post_data):
output_buffer = StringIO() # Initializes a string buffer that will be used to capture the
# returned JSON string from the Curl command
postfields = urlencode(post_data) # The form data we provide to Phabricator must be urlencoded -
# that is, formatted so that it can be transmitted as a URL.
c = pycurl.Curl() # Initialize a Curl object that will be used to send the data
c.setopt(c.URL, base_url + '/api/' + api_method) # Sets the URL that data should be sent to
c.setopt(c.POSTFIELDS, postfields) # Sets the request method to POST, Content-Type header to
# application/x-www-form-urlencoded, and data in request body.
c.setopt(c.WRITEFUNCTION, output_buffer.write) # Write output to the StringIO buffer
c.perform()
c.close()
parsed_json = json.loads(output_buffer.getvalue())
if parsed_json["error_code"] is not None:
raise Exception("PHAB: %s, %s" % (parsed_json["error_code"], parsed_json["error_info"]))
return parsed_json

Event Timeline

cspeckmim updated the paste's language from remarkup to python.
cspeckmim edited the content of this paste. (Show Details)
cspeckmim mentioned this in Z1336: General Chat.