网络编程
位置:首页>> 网络编程>> Python编程>> python操作jira添加模块的方法

python操作jira添加模块的方法

作者:晨+燕  发布时间:2022-01-20 12:41:42 

标签:python,jira,模块

JIRA介绍:

      JIRA是Atlassian公司出品的项目与事务跟踪工具,被广泛应用于缺陷跟踪、需求收集、流程审批、任务跟踪、项目跟踪和敏捷管理等工作领域.

      在开发工作中,Jira通常用作BUG管理和任务跟踪管理等,项目经理,测试人员,开发人员等在Jira上进行提交BUG,提交任务,修改任务进度等操作.下面我们看下python操作jira添加模块的方法。

python操作jira

首先安装jira模块

$ pip install jira

导入jira模块

from jira import JIRA
import xlrd # 导入xlrd,xlrd可以支持读取xls文件,不支持读取xlsx

编写添加模块代码

下面展示一些 内联代码片

def add_module_to_jira(jiraurl,username,password,modulename,projectKey):
   myjira = JIRA(jiraurl, basic_auth=(username, password))
   myjira.create_component(modulename,projectKey)

获取当前项目的模块信息

def get_project_compopents(jiraurl,username,password,projectKey):
   myjira = JIRA(jiraurl, basic_auth=(username, password))
   return  myjira.project_components(projectKey)

从excel表读取信息

def read_xls(xls_path,sheetName):
   worksheet = xlrd.open_workbook(xls_path)  # 打开excel文件,参数为文件的路径
   sheet_names = worksheet.sheet_names()  # 获取excel文件的所有sheet页,返回名字列表,
   # sheet_name=worksheet.sheet_by_name('Sheet1')#
   print(sheet_names)
   # print(sheet_name)
   sheet = worksheet.sheet_by_name(sheetName)  # 获取到sheet名称为Sheet1的sheet页
   row = sheet.nrows  # 获取文件行数
   cow = sheet.ncols  # 获取文件列数
   scores = sheet.col_values(4, 1, row)
   scoreslsit = []
   for score in scores:
       # scorelist = score.split('&')
       # print(scorelist)
       print(score)
       scoreslsit.append(score)
   return scoreslsit

主方法中调用添加模块等方法

ss=get_project_compopents(jiraurl,username,password,projectKey=projectkey)
   module=[]
   print(ss)
   for one in ss:
       print(one.name)
       module.append(one.name)
   print('ssss',len(ss))
   print(module)
   print("module:",len(module))
   modunameList = read_xls(r'D:\test9.xls', 'Sheet1')
   print(modunameList)
   print("modulist的长度",len(modunameList))
   modulenew=[]
   moduleold=[]
   for one in modunameList:
       if one in module:
           moduleold.append(one)
           continue
       else:
           modulenew.append(one)
   print("modulnew的内容如下:")
   print(modulenew)
   print("modulnew的长度是",len(modulenew))
   print("moduleOld是------------")
   print(moduleold)
   print("moduleOld是------------")
   for moduname in modulenew:
       print(moduname)
       add_module_to_jira(jiraurl=jiraurl,username=username,password=password,modulename=moduname,projectKey=projectkey)

来源:https://blog.csdn.net/wangchao_ad/article/details/123509125

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com