I'm developing software at a company, but at the development site, I get a lot of inquiries from sales people, saying, "The problem isn't happening at the evaluation site! It's happening at the site!"
The survey and answers to this inquiry will further exhaust the development members who are already exhausted.
It is unavoidable to receive inquiries from the field, but the problem is that the process from inquiry to answer is analog **.
However, it is troublesome because it is basically all exchanged by e-mail, and the current state is difficult to understand for each inquiry **, which is the worst situation.
I tried to improve this worst process as follows.
This makes management a lot easier.
In this article
** 3. Use Python to search the inquiry management table, and if a new inquiry is added, automatically register an issue in GitLab **
In connection with, I will introduce how to ** manage Gitlab issues with Python **.
You can operate GitLab with Python by using a package called ** python-gitlab **.
First, let's install python-gitlab with the pip install
command.
pip install python-gitlab
This is to connect to GitLab from Python, but GitLab is user-managed and inaccessible to anyone. Therefore, I will issue my own ** access token ** and use it to access GitLab in Python.
First, let's issue your own "access token" from the GitLab settings screen.
--Name: Give it an appropriate name for easy understanding. --Expiration date: You do not have to enter anything. In that case, the token will expire indefinitely. --Scope: Select api.
Press the button labeled "Create personal access token" to issue a token.
Let's ** save ** the character string of this token in Notepad etc. If you leave this page, you will never be able to confirm it.
In python-gitlab, set the necessary information in the config file and use that information to access GitLab. The access token issued above is also set in this config file.
Write the following content with a text editor and save it as ".python-gitlab.cfg" in the user folder (C: \ Users \ XXXX (user name)).
:.python-gitlab.cfg
[global]
default = gitlab
ssl_verify = true
timeout = 5
[gitlab]
url =GitLab URL
private_token =Personal access token
Thank you for your support. Now you are ready to go. Let's finally access GitLab with Python.
Although python-gitlab can also manage users and milestones, this article will explain the operation of issues (also called "issues" or "tickets").
See also the official documentation (https://python-gitlab.readthedocs.io/en/stable/gl_objects/issues.html) if needed.
Use the config file from earlier to access GitLab.
Python
import gitlab
gl = gitlab.Gitlab.from_config()
Then, use gl.projects.get ()
to specify the GitLab project ID and access the project.
Log in to GitLab to check your project ID.
Python
project_id = 1234567 #Project ID
project = gl.projects.get(project_id)
You now have an object for that project.
Now that you're ready, it's a little scary to register an issue suddenly. So first, let's see if we can refer to the issue.
I have registered such an issue in GitLab. Let's get these issues in Python.
Use project.issues.list ()
to get the issues registered in the project in a list.
After that, use the for statement to retrieve the issue objects one by one.
Python
issues = project.issues.list()
for issue in issues:
print("-------------------")
print("【title】", issue.title)
print("【Description】", issue.description)
print("【Status】", issue.state)
print("【Assignee】", issue.assignee["name"])
print("【Due date】", issue.due_date)
print("【Labels】", issue.labels)
Please refer to here for the attributes of issues.
The main attributes are listed below.
issue Attribute | meaning |
---|---|
id | ID |
title | title |
description | Description |
state | State (open/Close) |
assignee | Assignee |
due_date | Deadline |
labels | label |
Execution result
-------------------
[Title] Visit Seki-sensei's shop!
[Description] It's hard!
Next time, Mr. Seki wants to talk with Majolica about the store!
I have to do something about it!
[Condition] closed
【Assignee】 Doremi
【Due date】 2020-09-13
【Labels】 []
-------------------
[Title] Soaring purchase price
[Description] This month, the purchase price has more than doubled compared to last month.
I feel like Dela is crazy, but ... There is a story that the prices of the magic society are soaring recently.
Let me consider measures from next month onward with a view to changing suppliers.
[Condition] opened
【Assignee】 Doremi
【Due date】 2020-09-18
【Labels】 ['management']
-------------------
[Title] Suspicious person
[Description] Recently, I heard a rumor that a suspicious person who seems to be an old man is wandering around MAHO-do.
Would you like to take some measures?
[Condition] opened
【Assignee】 Doremi
【Due date】 2020-09-25
【Labels】 []
You were able to get it successfully.
Then, it is issue registration of the main subject.
Use project.issues.create ()
to register an issue.
Python
#Ticket registration
new_issue = project.issues.create({"title":"Autumn trip to Tohoku(Business trip sales)",
"description":"This year as well, I will go on a business trip sale called Autumn Travel.",
"due_date":"2020-10-20"})
print(new_issue.id)
Execution result
71385002
You have successfully registered!
Machines are better than humans in watching incoming emails, writing to management tables, and managing status. As long as the program is correct, the machine is faster and more accurate and won't complain even if you work 24 hours a day.
I think we are very happy to live in an era where we can work with such a convenient machine. Let's use machines (programs) to free yourself and your friends from boring work!
Recommended Posts