Snippets

Venkatesh-Prasad Ranganath Automate creation and modification of issues associated with bitbucket repositories

Updated by Venkatesh Ranganath

File modify_issues.py Modified

  • Ignore whitespace
  • Hide word diff
 # - https://confluence.atlassian.com/bitbucket/version-1-423626337.html
 # - https://confluence.atlassian.com/bitbucket/issues-resource-296095191.html
 
+# Depends on requests and requests_oauthlib packages (available via pip) 
+
 from requests_oauthlib import OAuth1Session
 
 client_key = 'Fill me'
Updated by Venkatesh Ranganath

File modify_issues.py Modified

  • Ignore whitespace
  • Hide word diff
 client_key = 'Fill me'
 client_secret = 'Fill me'
 
-if client_key == 'fill me' or client_secret == 'fill me':
+if client_key == 'Fill me' or client_secret == 'Fill me':
     raise RuntimeError('Provide key and secret')
 
 bitbucket = OAuth1Session(client_key, client_secret=client_secret)
Updated by Venkatesh Ranganath

File modify_issues.py Modified

  • Ignore whitespace
  • Hide word diff
 print(r)
 
 # create issues
-# each line in benchmarks.csv contains benchmark name and assignee  
+# each line in benchmarks.csv should contain benchmark name and assignee  
 with open("benchmarks.csv", "rt") as f:
     for line in f.readlines():
         tmp1 = line.strip().split(',')
Created by Venkatesh Ranganath

File modify_issues.py Added

  • Ignore whitespace
  • Hide word diff
+# Useful links
+# - https://confluence.atlassian.com/bitbucket/oauth-on-bitbucket-cloud-238027431.html
+# - https://confluence.atlassian.com/bitbucket/rest-apis-222724129.html
+# - https://confluence.atlassian.com/bitbucket/version-1-423626337.html
+# - https://confluence.atlassian.com/bitbucket/issues-resource-296095191.html
+
+from requests_oauthlib import OAuth1Session
+
+client_key = 'Fill me'
+client_secret = 'Fill me'
+
+if client_key == 'fill me' or client_secret == 'fill me':
+    raise RuntimeError('Provide key and secret')
+
+bitbucket = OAuth1Session(client_key, client_secret=client_secret)
+url = 'https://api.bitbucket.org/1.0/repositories/secure-it-i/android-app-vulnerability-benchmarks/issues'
+r = bitbucket.get(url)
+print(r)
+
+# create issues
+# each line in benchmarks.csv contains benchmark name and assignee  
+with open("benchmarks.csv", "rt") as f:
+    for line in f.readlines():
+        tmp1 = line.strip().split(',')
+        data = { 
+            'status':'new',
+            'priority':'blocker',
+            'title':'Create functional test for ' + tmp1[0],
+            'responsible':tmp1[1],
+            'kind':'enhancement'
+        }
+        print(data)
+        r = bitbucket.post(url, data = data)
+        print(r)
+        r.close()
+
+## delete issues
+#for i in range(77, 117):
+#    r = bitbucket.delete(url + "/" + str(i))
+#    print(r)
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.