|
#!/usr/bin/python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# redmineorg_copy_sub.py
|
|
# redmine本家コピー用処理の関数部分抜き出し
|
|
|
|
def get_affected_version(issue_org,cf_id):
|
|
|
|
# 発見バージョンのIDをCFから取得して返す
|
|
affected_version=0
|
|
if hasattr(issue_org, 'custom_fields'):
|
|
|
|
cf=issue_org.custom_fields
|
|
|
|
cf_affected_version=cf.get(cf_id)
|
|
if getattr(cf_affected_version,'value',False):
|
|
affected_version=int(cf_affected_version.value)
|
|
|
|
return(affected_version)
|
|
|
|
|
|
def get_comments_plus1_journals(issue_org):
|
|
|
|
# 本家チケットの+1数と、コメント全体の文字列を作成して返す
|
|
plus1=0
|
|
comments=0
|
|
journals=""
|
|
for journal in issue_org.journals:
|
|
if hasattr(journal, 'notes'):
|
|
comments=comments+1
|
|
journals=journals+journal.notes+'\n'
|
|
journals=journals+('-'*80)+'\n'
|
|
|
|
if ((journal.notes).strip()[0:2]=='+1'):
|
|
plus1=plus1 +1
|
|
|
|
comments=len(issue_org.journals)
|
|
return comments,plus1,journals
|
|
|
|
|
|
def get_relations(redmine_org,issue_org):
|
|
|
|
# 関連付けを文字列化して返す。
|
|
|
|
# redmine_org redmine本家
|
|
# issue_org redmine本家の元チケット
|
|
|
|
relations=issue_org.relations
|
|
relations_count=len(relations)
|
|
|
|
relations_str_all=''
|
|
|
|
for i in range(0,relations_count):
|
|
relation_str=''
|
|
# issue_to_id',issue_id', 自分以外を返す
|
|
relation_id=relations[i].issue_to_id
|
|
if (issue_org.id==relation_id):
|
|
relation_id=relations[i].issue_id
|
|
related_issue_subject=redmine_org.issue.get(relation_id).subject
|
|
|
|
relation_str=relations[i].relation_type+","+redmine_org.issue.get(relation_id).status.name+","+str(relation_id)+","+related_issue_subject+'\n'
|
|
# print(relation_str)
|
|
relations_str_all = relations_str_all+ relation_str
|
|
|
|
return relations_count,relations_str_all
|
|
|
|
|
|
def issue_org_copy(issue_org,redmine_org,redmine_org_url,redmine_dst,redmine_dst_pj,vote_tracker_id):
|
|
|
|
issue_org_id=issue_org.id
|
|
|
|
# 各属性は、未定義の場合を考慮して対応必要。
|
|
# 最初に初期値を設定し、属性の存在を確認してから設定する。
|
|
|
|
category_id=0
|
|
if hasattr(issue_org, 'category'):
|
|
category_id= issue_org.category.id
|
|
|
|
fixed_version_id=0
|
|
if hasattr(issue_org, 'fixed_version'):
|
|
fixed_version_id= issue_org.fixed_version.id
|
|
|
|
status_id=0
|
|
if hasattr(issue_org, 'status'):
|
|
status_id=issue_org.status.id
|
|
|
|
tracker_id=0
|
|
if hasattr(issue_org, 'tracker'):
|
|
tracker_id=issue_org.tracker.id
|
|
|
|
author_id=0
|
|
if hasattr(issue_org, 'author'):
|
|
author_id= issue_org.author.id
|
|
|
|
assigned_to_id=0
|
|
if hasattr(issue_org, 'assigned_to'):
|
|
assigned_to_id= issue_org.assigned_to.id
|
|
|
|
# 転送元チケットのCFの存在を確認し、存在すればそのCF内容を取得し設定する
|
|
# 今回は redmine.orgのaffected_version(4)のみ対応
|
|
# CFが全く無い場合も有り得る。
|
|
|
|
affected_version=get_affected_version(issue_org,4)
|
|
if affected_version==0:
|
|
affected_version=''
|
|
|
|
|
|
# 本家チケットの+1数と、コメント全体の文字列を作成する
|
|
comments,plus1,journals= get_comments_plus1_journals(issue_org)
|
|
|
|
# relations
|
|
relations_count,relations_str_all=get_relations(redmine_org,issue_org)
|
|
|
|
# 転送先チケット作成
|
|
# 転送先の内容設定
|
|
|
|
issue = redmine_dst.issue.new()
|
|
|
|
issue.subject = issue_org.subject
|
|
issue.description =issue_org.description
|
|
issue_org_url=redmine_org_url + '/issues/' + str(issue_org_id)
|
|
#
|
|
# 以下は同じ
|
|
issue.project_id = redmine_dst_pj
|
|
issue.tracker_id = vote_tracker_id #トラッカー(vote=4)
|
|
|
|
issue.status_id = issue_org.status.id
|
|
issue.category_id = category_id
|
|
issue.fixed_version_id =fixed_version_id
|
|
|
|
# redmine.orgのpriority数値は古いので、-2する必要がある。
|
|
# そうしないと6などの数値で範囲外としてエラーになる
|
|
issue.priority_id = issue_org.priority.id -2
|
|
|
|
if getattr(issue_org,'start_date',False):
|
|
issue.start_date = issue_org.start_date
|
|
|
|
if getattr(issue_org,'due_date',False):
|
|
issue.start_date = issue_org.due_date
|
|
|
|
if getattr(issue_org,'closed_on',False):
|
|
issue.closed_on = issue_org.closed_on
|
|
|
|
if getattr(issue_org,'estimated_hours',False):
|
|
issue.estimated_hours = issue_org.estimated_hours
|
|
if getattr(issue_org,'done_ratio',False):
|
|
issue.done_ratio = issue_org.done_ratio
|
|
|
|
# 今回は、watcher,parentは使っていない
|
|
# issue.watcher_user_ids = [1,3] # ウォッチするユーザのID
|
|
# issue.parent_issue_id = 0 # 親チケットのID
|
|
|
|
issue.custom_fields = [{'id': 4, 'value': issue_org_url}]
|
|
issue.custom_fields = [{'id': 5, 'value': category_id}]
|
|
issue.custom_fields = [{'id': 6, 'value': fixed_version_id}]
|
|
issue.custom_fields = [{'id': 7, 'value': issue_org_id}]
|
|
issue.custom_fields = [{'id': 8, 'value': author_id}]
|
|
issue.custom_fields = [{'id': 9, 'value': journals}]
|
|
issue.custom_fields = [{'id': 10,'value': assigned_to_id}]
|
|
issue.custom_fields = [{'id': 11,'value': comments}]
|
|
issue.custom_fields = [{'id': 12,'value': status_id}]
|
|
issue.custom_fields = [{'id': 13,'value': tracker_id}]
|
|
issue.custom_fields = [{'id': 14,'value': plus1}]
|
|
issue.custom_fields = [{'id': 15,'value': affected_version}]
|
|
issue.custom_fields = [{'id': 16, 'value': relations_str_all}]
|
|
|
|
# issue.uploads = [{'path': '/share/test.txt'}]
|
|
issue.save()
|
|
|
|
|