Getting issue comments JIRA python - python

I am trying to get all comments of issues created in JIRA of a certain search query. My query is fairly simple:
import jira
from jira.client import JIRA
def fetch_tickets_open_yesterday(jira_object):
# JIRA query to fetch the issues
open_issues = jira_object.search_issues('project = Support AND issuetype = Incident AND \
(status = "Open" OR status = "Resolved" OR status = "Waiting For Customer")', maxResults = 100,expand='changelog')
# returns all open issues
return open_issues
However, if I try to access the comments of tickets created using the following notation, I get a key error.
for issue in issues:
print issue.raw['fields']['comment']
If I try to get comments of a single issue like below, I can access the comments:
single_issue = jira_object.issue('SUP-136834')
single_issue.raw['fields']['comment']
How do I access these comments through search_issues() function?

The comment field is not returned by the search_issues method you have to manually state the fields that must be included by setting the corresponding parameter.
just include the 'fields' and 'json_result' parameter in the search_issue method and set it like this
open_issues = jira_object.search_issues('project = Support AND issuetype = Incident AND \
(status = "Open" OR status = "Resolved" OR status = "Waiting For Customer")', maxResults = 100,expand='changelog',fields = 'comment',json_result ='True')
Now you can access the comments without getting keytype error
comm=([issue.raw['fields']['comment']['comments'] for issue in open_issues])

I struggled with the same issue. Assuming "issue" is an object of type Issue, and "jira" is an object of type JIRA, according to http://jira.readthedocs.org/en/latest/#issues
issue.fields.comment.comments
should work, but the fields object does not have any key "comment".
The other option mentioned there works for me:
jira.comments(issue)
So, for it to work you use the issues from your search result and call jira.comments. E.g.
issues = jira.search_issues(query)
comments = jira.comments(issues[index])
(My version of the library is 1.0.3, python 2.7.10)

from jira import JIRA
Jira = JIRA('https://jira.atlassian.com')
issue_num = "ISSUE-123"
issue = Jira.issue(issue_num)
comments = issue.fields.comment.comments
for comment in comments:
print("Comment text : ",comment.body)
print("Comment author : ",comment.author.displayName)
print("Comment time : ",comment.created)

Related

I am trying to update data but it doesn't get updated in the database

I am new to python and Mongo db. What am I trying to do is that I want to update data in my database and code seems to be working fine. But, still the data doesn't get updated in the database.
I have tried functions like update and update_one etc. But still no luck so far.
#app.route("/users/update_remedy", methods = ['POST'])
def update_remedy():
try:
remedy = mongo.db.Home_Remedies
name = request.get_json()['name']
desc = request.get_json()['desc']
print("S")
status = remedy.update_one({"name" : name}, {"$set": {"desc" : desc}})
print("h")
return jsonify({"result" : "Remedy Updated Successfully"})
except Exception:
return 'error'
It's likely that your update_one call is looking for a document that doesn't exist. If the query on a vanilla update doesn't return any documents then no update operation will be performed. Make sure that a doc with the field {"name" : name}
actually exists. You could also check the return value from the update_one to ensure an update happened. See UpdateResult for details.

How to get the options for a custom field in Jira?

In the Jira issue I'm looking at, there are fields with a drop down list for valid values. I would like to access that drop down list using python. When looking at the returned fields for the issue, the object has a value customfield_14651 which is an object with value and id. Jira documentation shows there is a custom_field_option() method which should return the fields? I call the method like below:
self.jira = JIRA('https://jira.companyname.com',basic_auth (login['username'], login['password']) )
print self.jira.custom_field_option('14651')
and receive back the following error:
response text = {"errorMessages":["A custom field option with id '14651' does not exist"],"errors":{}}
Jira has the .fields() function which returns a list of all fields that are visible to the account you are using.
from jira import JIRA
jira = JIRA(basic_auth=('username', 'password'), options = {'server': 'url'})
# Fetch all fields
allfields = jira.fields()
# Make a map from field name -> field id
name_map = {field['name']:field['id'] for field in allfields}
name_map is now a dict in the format of {"field name":"customfield_xxxx", ... }
It looks like the way to do this in the API is:
from jira import JIRA
jira = JIRA(basic_auth=('username', 'password'), options = {'server': 'url'})
# get an example issue that has the field you're interested in
issue = jira("PRJ-1")
meta = jira.editmeta(issue)
# inspect the meta to get the field you want to look at
allowed_values = [v['value'] for v in meta['fields']['customfield_99999']['allowedValues']]

Getting Fault 1: "SQLSTATE[21000]: Cardinality violation: 1241

While creating a customer with Magento API using Python, i am getting this error:
Fault 1: "SQLSTATE[21000]: Cardinality violation: 1241 Operand should contain 1 column(s), query was: SELECT `customer_entity`.* FROM `customer_entity` WHERE (entity_id ='firstname', '3876')"
But if i specify only the customer id, it will ask for all the other fields, and when i extend the dict with these values, the same error comes again.
Here is the dict i use to create the customer:
address = {}
address['customer_id'] = '3876'
address['addressdata']={}
address['addressdata']['firstname'] = 'firstname'
address['addressdata']['lastname'] = 'lastname'
address['addressdata']['city'] = 'city'
address['addressdata']['region'] = 'Texas'
address['addressdata']['region_id'] = 1
address['addressdata']['postcode'] = '23423' #ZIP
address['addressdata']['telephone'] = '3245235235' #phone
address['addressdata']['is_default_billing'] = False
address['addressdata']['is_default_shipping'] = False
address = proxy.call(session, 'customer_address.create', [address])
What do you think can be wrong here? Thanks
On the server side, enable sql logging (ideally only your API call should run against that server, in order to debug):
In Varien_Db_Adapter_Pdo_Mysql
lib/varien/Db/Adapter/Pdo/Mysql.php
set
protected $_debug = true;
protected $_logAllQueries = true;
and (if nor already there) create the folder defined in
protected $_debugFile = 'var/debug/sql.txt';
Run the API call then have a look at the log file and see what queries ran and why it gives an error.
You can also try these following links for same issue, might be helpfull for you.
https://stackoverflow.com/a/14864123
https://stackoverflow.com/a/34997348
https://stackoverflow.com/a/38326377

Recurly API returning 500 error

I am following the example code snippets the one in the right panel here. So I have a Recurly token and am trying to start a subscription using it.
subscription = Subscription()
subscription.plan_code = 'monthly'
subscription.currency = 'USD'
account = Account(account_code='1a')
account.email = 'mark#example.com'
account.first_name = 'mark'
account.last_name = 'lname'
billing_info = BillingInfo()
billing_info.number = '4111-1111-1111-1111'
billing_info.month = 1
billing_info.year = 2019
account.billing_info = billing_info
subscription.account = account
subscription.save()
I get error 500 when the code above runs. If I comment out subscription.save() the logs show ParseError: mismatched tag: line 6, col 2 which seems like xml parsing error. I get no error(but of course I presume the subscription is not being saved). Could this error be as a result of testing many times? or what could be the issue? am using sandbox.
My bad. I was missing recurly.SUBDOMAIN together with recurly.RECURLY_API_KEY settings. All save() methods for recurly.Subscription(), recurly.BillingInfo(), recurly.Account() were throwing the error when called.

How to update labels for the issues present in Jql query/Filter

My requirement is: I want to update the labels for the issues present in the filter.
import jira.client
from jira.client import jira
options = {'server': 'https://URL.com"}
jira = JIRA(options, basic_auth=('username], 'password'))
issue = jira.search_issues('jqlquery')
issue.update(labels=['Test']
I'm getting attribute error which states that 'Resultlist' object has no attibute 'update'.
Update only works on a single issue. Search_issues returns a ResultList.
The JIRA API does not support bulk change. However, you can loop over the issues yourself and do the update for each one. Something like:
import jira.client
from jira.client import jira
options = {'server': 'https://URL.com'}
jira = JIRA(options, basic_auth=('username', 'password'))
issues = jira.search_issues('jqlquery')
for issue in issues:
issue.update(labels=['Test'])
It's documented in the jira-python docs at http://jira-python.readthedocs.org/en/latest/
You might have to also do
issue = jira.issue(issue.key)
to get a modifiable objects
# You can update the entire labels field like this
issue.update(labels=['AAA', 'BBB'])
# Or modify the List of existing labels. The new label is unicode with no spaces
issue.fields.labels.append(u'new_text')
issue.update(fields={"labels": issue.fields.labels})

Categories