环境依赖 : 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)

  

   

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

  1. Python中根据时间自动创建文件夹

    导语 ​ 电脑桌面文件太多查找起来比较花费时间,并且凌乱的电脑桌面也会影响工作心情,于是利用python根据时间自动建立当日文件夹,这样就可以把桌面上文件按时间进行存放. 代码实现 # _*_codi ...

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

    最近在一个博客联盟的微信群里面看到经常有朋友问阿里云的ecs服务器怎么设置自动创建快照,也不知道最近是怎么了,看到问这个问题的朋友有有四五个左右了,今天就特意到博客里来费大家分享设置自动创建快照的方法 ...

  3. Python 官方中文教程(简)

    Python 官方教程 前言 这是一次系统学习Python官方教程的学习笔记 整个教程一共16章, 在学习过程中记录自己不知道的和一些重要的知识, 水平有限, 请指正. Python3.7 官方教程. ...

  4. Python Numpy基础教程

    Python Numpy基础教程 本文是一个关于Python numpy的基础学习教程,其中,Python版本为Python 3.x 什么是Numpy Numpy = Numerical + Pyth ...

  5. Python解释器安装教程以及环境变量配置 以及 pycharm的安装与激活

    计算机的组成 主板:人的骨架,用于拓展设备 CPU:人的大脑,用于计算和逻辑处理 硬盘:存储数据(永久储存),比如电脑上的 C盘,D盘 内存:临时记忆(断电即消失) 操作系统:XP win7 win1 ...

  6. HelloDjango 系列教程:创建 Django 博客的数据库模型

    文中涉及的示例代码,已同步更新到 HelloGitHub-Team 仓库 设计博客的数据库表结构 博客最主要的功能就是展示我们写的文章,它需要从某个地方获取博客文章数据才能把文章展示出来,通常来说这个 ...

  7. 面系那个对象开发原则.高内聚.低耦合+Python安装详细教程+print输出带颜色的方法

    面系那个对象开发原则.高内聚.低耦合 软件设计中通常用耦合度和内聚度作为衡量模块独立程度的标准.划分摸块的一个准则就是高内聚低耦合. 这是软件工程中的概念,是判断设计好坏的标准,主要是面向OO的设计, ...

  8. 史上最全Python快速入门教程,满满都是干货

    Python是面向对象,高级语言,解释,动态和多用途编程语言.Python易于学习,而且功能强大,功能多样的脚本语言使其对应用程序开发具有吸引力.Python的语法和动态类型具有其解释性质,使其成为许 ...

  9. Python验证码6位自动生成器

    Python验证码6位自动生成器

随机推荐

  1. php常见的关键字

    一 instanceof 检测一个对象是否属于某个类型 <?php class A { } $a = new A(); if($a instanceof A) { echo "yes& ...

  2. ArcGisEngineForJava开发

    ArcGIS Engine control examples 一.利用Visual JavaBeans来构建应用程序 这种方案是针对使用可视化的Java组件,想要来构建和部署应用程序的开发人员.Jav ...

  3. asp.net DataTable 修改列值

    /// <summary> /// 修改数据表DataTable某一列的类型和记录值(正确步骤:1.克隆表结构,2.修改列类型,3.修改记录值,4.返回结果) /// </summa ...

  4. 使用jQuery实现点击左右滑动切换特效

    使用jQuery实现点击左右滑动切换特效: HTML代码如下: <!--整体背景div--> <div class="warp"> <!--中间内容d ...

  5. Android新手踩到的一些雷,记录一下~

    这两天在搞一个android的app ,由于是新手,注定要踩很多坑. 这里是一些遇到的一些问题,网上各种找答案,感谢各位博主.这里记录一下,留待以后再看. 1. android layout_weig ...

  6. Entity Framework Linq 动态组合where条件

    public static class PredicateExtensions { public static Expression<Func<T, bool>> True&l ...

  7. css中clearfix清除浮动的用法及其原理示例介绍

    clearfix的定义: .clearfix:after {}{ content: "."; /**//*内容为“.”就是一个英文的句号而已.也可以不写.*/ display: b ...

  8. vs2008下面wince错误MSDiscoCodeGenerator

    引用webservice时候错误.网上也有很多解决方法,各不相同. 不多说了. 打开vs2008安装包 找到wcu目录下面有个NetCF 目录: 下面的NetCFSetupv2.msi,NetCFSe ...

  9. 从C++转向Java的第一课

    序:计算机语言的学习,最快捷的方法是从一种语言映射到另一种语言.Java和C++作为最通用的面相对象高级语言,不论从语法或者编程上都极具相似性和可效仿行,这里的可效仿包括——语法理解可效仿和编程规范可 ...

  10. nodejs渲染模板

    为什么要用nodejs来渲染? 之前前端的任务就是用HTML+CSS 来高保真的还原UI所设计原图,偶尔会使用少量的jq来对页面添加一些特效,页面还要交付给后端开发人员进行数据填充(php jsp)等 ...