LoginSignup
1
0

More than 3 years have passed since last update.

JIRAのOpenプロジェクトをGoogle spreadsheetに自動転記する

Posted at

社外 vs 社内のプロジェクト管理環境差をどうするか問題

クライアント側ではJIRAを使って管理をしているのですが、社内ではBacklogを使っています。これには幾つかの理由が絡み合っています。

  • 案件に紐づけて売上金額やクライアントには見せたくないコメント(あいつクソ)等も一緒に管理したい
  • プロジェクトにかかわるすべての人のJIRAアカウントは発行してくれない
  • グローバルクライアントで全部英語(社内全員がスムーズに英語でJIRAでガツガツやれるわけではない)
  • JIRAも本社のリージョンにあるせいなのかクソ重くて使い物にならない

なのでやっぱり表のようなものにJIRAの内容をまんま転記するのが漏れやミスもなくてよいのかと思い試してみました。

やったこと

  • JIRAのRest APIでOpenプロジェクトの取得
  • 整形
  • Google Spreadsheetに転記

いちおう重たい重たいJIRAで検索してコピペする、みたいな不毛な作業はなくなりました。
細かい運用改善はこれからです。

実装

jira.py
import base64
import requests
from google.colab import files
import pandas as pd
from google.colab import auth
auth.authenticate_user()
import gspread
import gspread_dataframe as gs_df
from oauth2client.client import GoogleCredentials

gc = gspread.authorize(GoogleCredentials.get_application_default())

# Speradsheetファイル名を指定してシートを開く
worksheet = gc.open('ファイル名').worksheet('シート名')

base_url = 'https://jira.yourjira.com/'
authstr  = 'yourID:yourPW'
authkey  = base64.encodebytes(authstr.encode('utf-8')).decode('ascii')
auth_header = {'Content-Type':'application/json', 'Authorization':'Basic ' + repr(authkey)}

#トータル件数を見る
searchUrl=base_url+'/rest/api/2/search?jql=project+yourproject+AND+resolution+%3D+Unresolved'
result =requests.get(searchUrl, headers=auth_header)
result =result.json()
total=str(result['total'])
print('トータル案件数:'+total+'件')

#取得内容(Fields)を指定して全件取得
searchUrl=base_url+'/rest/api/2/search?maxResults='+total+'&fields=issuetype,summary,assignee&jql=project+%3D+yourproject+AND+resolution+%3D+Unresolved+ORDER+BY+updated+DESC'
result =requests.get(searchUrl, headers=auth_header)
result =result.json()
issues=result['issues']

#出力
with open('example.csv', 'w') as f:
  f.write("Type,URL,Summary,Assignee,Reporter,Duedate,Updated\n")
  for issue in issues:
    if issue['fields']['assignee'] is None:
      assignee=""
    else:
      assignee=issue['fields']['assignee']['displayName']
    if issue['fields']['duedate'] is None:
      duedate=""
    else:
      duedate=issue['fields']['duedate']
    f.write(issue['fields']['issuetype']['name']+',https://jira.yourjira.com/browse/'+issue['key']+',"'+issue['fields']['summary']+'",'+assignee+','+issue['fields']['reporter']['displayName']+','+duedate+','+issue['fields']['updated']+'\n')

#CSVで落とす場合
#files.download('example.csv')

#スプレッドシートに書き出す場合
df = pd.read_csv('example.csv')
gs_df.set_with_dataframe(worksheet, df)

できました。
2020-08-06_08h44_51.png

まとめ

JIRAはページ開いて検索するよりAPIの方が速いですね。ページ読み込み・表示で何秒もかかるイラつきを押さえる観点でもよかったかもです。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0