【python】jiraAPI使用教程 自动创建jira问题单并置状态为OPEN

环境依赖 : python库 redis jira  

安装命令:pip install redis

pip install jira

redis服务安装命令:

$sudo apt-get update

$sudo apt-get install redis-server

启动 Redis

$ redis-server

查看 redis 是否启动?

                  $ redis-cli

以上命令将打开以下终端:

                  redis 127.0.0.1:6379>

127.0.0.1 是本机 IP ,6379 是 redis 服务端口。现在我们输入 PING 命令。

                  redis 127.0.0.1:6379> ping PONG

AutoCreateIssue


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

#!/usr/bin/python

# -*- coding:utf-8 -*-

from jira import JIRA

import sys, getopt, redis, os

class JiraTool:

    def __init__(self):

        self.server = https:/jira。example.net‘

        self.basic_auth = (‘username‘, ‘password‘)

        self.jiraClinet = None

    def login(self):

        self.jiraClinet = JIRA(server=self.server, basic_auth=self.basic_auth)

        if self.jiraClinet != None:

            return True

        else:

            return False

    def findIssueById(self, issueId):

        if issueId:

            if self.jiraClinet == None:

                self.login()

            return self.jiraClinet.issue(issueId)

        else:

            return ‘Please input your issueId‘

    def createIssue(self, description, assignee, project, parent, filepath):

        issue_dict = {

            ‘project‘: {‘key‘: project},

            ‘issuetype‘: {‘name‘: ‘Sub-Task‘},

            ‘parent‘: {‘key‘: parent},

            ‘summary‘: ‘[xxx]Auto sync file %s from storage-cnn to storage‘%(filepath),

            ‘description‘: description,

            ‘assignee‘: {‘name‘: assignee},

            ‘customfield_12603‘: {‘value‘: ‘xxx‘},

            ‘components‘: [{‘name‘: ‘SCM‘}],

            ‘priority‘: {‘name‘: ‘Major‘},

        }

        if self.jiraClinet == None:

            self.login()

        return self.jiraClinet.create_issue(issue_dict)

if __name__ == ‘__main__‘:

    redisTool = redis.Redis(host=‘127.0.0.1‘, port=6379)

    jiraTool = JiraTool()

    jiraTool.login()

    description = ‘‘

    assignee = ‘‘

    watchers = None

    project = ‘‘

    parent = ‘‘

    openIssuekey = ‘‘

    cnnStoragePath = xxxxx‘

    opts, args = getopt.getopt(sys.argv[1:], ‘d:a:w:p:o:‘)

    for op, value in opts:

        if op == ‘-d‘:

            filepath = value

        elif op == ‘-a‘:

            user = jiraTool.jiraClinet.search_users(user=value)

            if user:

                assignee = user[0].key

            else:

                print (‘Please make sure that the user email is correct!‘)

                sys.exit(-1)

        elif op == ‘-p‘:

            if ‘Austin‘ in value:

                project = ‘xxxx‘

                parent = ‘xxxx‘

                cnnStoragePath = os.path.join(cnnStoragePath,‘xxxx‘)

            elif ‘Ford‘ in value:

                project = ‘xxxxx‘

                parent = ‘xxxxx‘

                cnnStoragePath = os.path.join(cnnStoragePath,‘xxxxx‘)

            else:

                print (‘Please make sure that the project is correct!‘)

                sys.exit(-1)

        elif op == ‘-w‘:

            watchers = value.split(‘,‘)

        elif op == ‘-o‘:

            openIssuekey = value

            if not openIssuekey:

                print (‘Please make sure that the openIssuekey is correct!‘)

                sys.exit(-1)

            break

    try:

        if openIssuekey:

            issuekeyTmp = redisTool.get(openIssuekey)

            issue = jiraTool.findIssueById(issuekeyTmp)

            print openIssuekey, ‘----‘, issuekeyTmp, ‘----‘, issue.fields.status

            if ‘Screen‘ in str(issue.fields.status):

                print ‘Update %s status screen ----> open ‘ % (issuekeyTmp)

                jiraTool.jiraClinet.transition_issue(issue, 151)

                redisTool.delete(openIssuekey)

            else:

                print ‘Please make sure the issue status is not screen‘

        else:

            if not filepath:

                print(‘Please make sure that the file path is correct!‘)

                sys.exit(-1)

            if not assignee:

                print(‘Please make sure that the assignee is correct!‘)

                sys.exit(-1)

            if not project:

                print (‘Please make sure that the project is correct!‘)

                sys.exit(-1)

            print(‘Creating issue now‘)

            cnnStoragePath = os.path.join(cnnStoragePath,filepath)

            description = ‘[Files to sync]\n‘ + cnnStoragePath

            print "cnnStoragePath: " + cnnStoragePath

            print "description: " + description

            print "assignee: " + assignee

            issue = jiraTool.createIssue(description, assignee, project, parent,filepath)

            issueKey = issue.key

            redisTool.set(filepath, issueKey)

            print(‘issue key is ---->‘, issueKey)

            if watchers:

                for watcherItem in watchers:

                    watcher = jiraTool.jiraClinet.search_users(user=watcherItem)

                    if watcher:

                        watcherKey = watcher[0].key

                        jiraTool.jiraClinet.add_watcher(issue=issueKey, watcher=watcherKey)

                    else:

                        print(‘%s user does not exis‘ % (watcherItem))

                        jiraTool.jiraClinet.add_comment(issue=issueKey, body=‘%s user does not exis‘ % (watcherItem))

    except Exception as e:

        print e

        sys.exit(-1)

  

   
时间: 2024-12-16 09:38:53

【python】jiraAPI使用教程 自动创建jira问题单并置状态为OPEN的相关文章

python2.7自动创建虚拟机

python2.7自动创建虚拟机,单台.多台(IP为虚拟机名) [1].[代码] [Python]代码 跳至 [1] ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66

K8s数据持久化之自动创建PV

在前两篇实现k8s的数据持久化的流程为:搭建nfs底层存储===>创建PV====>创建PVC===>创建pod.最终pod中的container实现数据的持久化. 上述流程中,看似没什么问题,但细想一下,PVC在向PV申请存储空间的时候,是根据指定的pv名称.访问模式.容量大小来决定具体向哪个PV来申请空间的,如果PV的容量为20G,定义的访问模式是WRO(只允许以读写的方式挂载到单个节点),而PVC申请的存储空间为10G,那么一旦这个PVC是向上面的PV申请的空间,也就是说,那个PV

使用python脚本自动创建pip.ini配置文件

运行一下python代码自动创建pip/pip.ini文件并添加pip源 """ python建立pip.ini.py 2016年4月30日 03:35:11 codegay """ import os ini="""[global] index-url = https://pypi.doubanio.com/simple/ [install] trusted-host=pypi.doubanio.com "

阿里云ecs自动创建快照教程

最近在一个博客联盟的微信群里面看到经常有朋友问阿里云的ecs服务器怎么设置自动创建快照,也不知道最近是怎么了,看到问这个问题的朋友有有四五个左右了,今天就特意到博客里来费大家分享设置自动创建快照的方法. 首先进入正题,我们登录阿里云控制台,然后在控制台的点击ecs服务器,在点击需要设置自动创建快照的服务器,然后在界面上点击本实例磁盘,在右边就能看到设置自动快照策略的按钮了.在快照设置界面上我们可以给快照取个名字,然后在快照的创建时间和保留天数就可以了. 总结:进入到ecs服务器控制台,然后点击需

Python验证码6位自动生成器

Python验证码6位自动生成器 !/usr/bin/env python # -*- coding:utf-8 -*- import random tem = "" for i in range(6): digi = random.randrange(0,11) if digi == 1 or digi == 5: ####当randrange(0,11)随机生成数是1或5的时候 ,,,,:)是不是有点绕啊,哈哈哈 num = random.randrange(1,10) num =

bat文件自动创建cocos2dx 工程

1. 写在开头 本人写了一个自动创建cocos2dx工程的脚本..bat文件,会修正Application.mk 文件,并且在桌面创建打开项目目录的快捷方式. 使用条件:1. 在本地计算机中已安装python 2.7.6 版本,并将python安装目录加入到 PATH环境变量中. 2. 根据自己的cocos2dx与ndk安装目录,更改脚本最初COCOS2DX_DIR.NDK_DIR变量. 3.本脚本只创建c++语言的cocos2dx工程,创建成功后仍需手动配置c++ build目录. 个人写的脚

Python+Django+SAE系列教程11-----request/pose/get/表单

表单request,post,get 首先我们来看看Request对象,在这个对象中包含了一些有用的信息,学过B/S开发的人来说这并不陌生,我们来看看在Django中是如何实现的: 属性/方法 说明 举例 request.path 除域名以外的请求路径,以正斜杠开头 "/hello/" request.get_host() 主机名(比如,通常所说的域名) "127.0.0.1:8000" or"www.example.com" request.g

Python中Generators教程

转载至:https://www.bytelang.com/article/content/NQbmUaRIXyA= 要想创建一个iterator,必须实现一个有__iter__()和__next__()方法的类,类要能够跟踪内部状态并且在没有元素返回的时候引发StopIteration异常. 这个过程很繁琐而且违反直觉.Generator能够解决这个问题. python generator是一个简单的创建iterator的途径.前面讲的那些繁琐的步骤都可以被generator自动完成. 简单来说

七牛云存储Python SDK使用教程 - 上传策略详解

文 七牛云存储Python SDK使用教程 - 上传策略详解 七牛云存储 python-sdk 七牛云存储教程 jemygraw 2015年01月04日发布 推荐 1 推荐 收藏 2 收藏,2.7k 浏览 本教程旨在介绍如何使用七牛的Python SDK来快速地进行文件上传,下载,处理,管理等工作. 前言 我们在上面的两节中了解到,客户端上传文件时,需要从业务服务器申请一个上传凭证(Upload Token),而这个上传凭证是业务服务器根据上传策略(PutPolicy)来生成的,而这个生成过程中