Skip to content

Commit 01f3dba

Browse files
committed
examples: Add create.py
1 parent e63d366 commit 01f3dba

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

examples/create.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env python
2+
#
3+
# This program is free software; you can redistribute it and/or modify it
4+
# under the terms of the GNU General Public License as published by the
5+
# Free Software Foundation; either version 2 of the License, or (at your
6+
# option) any later version. See http://www.gnu.org/copyleft/gpl.html for
7+
# the full text of the license.
8+
9+
# create.py: Create a new bug report
10+
11+
from __future__ import print_function
12+
13+
import time
14+
15+
import bugzilla
16+
17+
# public test instance of bugzilla.redhat.com.
18+
#
19+
# Don't worry, changing things here is fine, and won't send any email to
20+
# users or anything. It's what partner-bugzilla.redhat.com is for!
21+
URL = "partner-bugzilla.redhat.com"
22+
bzapi = bugzilla.Bugzilla(URL)
23+
if not bzapi.logged_in:
24+
print("This example requires cached login credentials for %s" % URL)
25+
bzapi.interactive_login()
26+
27+
28+
# Similar to build_query, build_createbug is a helper function that handles
29+
# some bugzilla version incompatibility issues. All it does is return a
30+
# properly formatted dict(), and provide friendly parameter names.
31+
# The argument names map to those accepted by XMLRPC Bug.create:
32+
# https://bugzilla.readthedocs.io/en/latest/api/core/v1/bug.html#create-bug
33+
#
34+
# The arguments specified here are mandatory, but there are many other
35+
# optional ones like op_sys, platform, etc. See the docs
36+
createinfo = bzapi.build_createbug(
37+
product="Fedora",
38+
version="rawhide",
39+
component="python-bugzilla",
40+
summary="new example python-bugzilla bug %s" % time.time(),
41+
description="This is comment #0 of an example bug created by "
42+
"the python-bugzilla.git examples/create.py script.")
43+
44+
newbug = bzapi.createbug(createinfo)
45+
print("Created new bug id=%s url=%s" % (newbug.id, newbug.weburl))

0 commit comments

Comments
 (0)