search
HomeBackend DevelopmentPython TutorialBuilding a Python code review scheduler: review follow-up

Building a Python code review scheduler: review follow-up

In part three of this series, you learned how to save code review request information for later processing. You create a method called read_email to get an email from the inbox to check whether the reviewer has responded to the code review request. You also implemented error handling in the code review scheduler code.

In this part of the series, you will use your saved code review information and information from your email to check whether the reviewer has responded to the review request. If the request has not been responded to, you will send a follow-up email to the reviewer.

start using

First clone the source code of the third part of this tutorial series.

git clone https://github.com/royagasthyan/CodeReviewer-Part3 CodeReviewer

Modify the config.json file to include some relevant email addresses and keep the royagasthyan@gmail.com email address. This is because git has a commit associated with this specific email address, which is required for the code to execute as expected. Modify the SMTP credentials in the schedule.py file:

FROM_EMAIL      = "your_email_address@gmail.com"
FROM_PWD        = "your_password"

Navigate to the project directory CodeReviewer and try executing the following command in the terminal.

python scheduler.py -n 20 -p "project_x"

It should send the code review request to a random developer for review and create a reviewer.json file containing the review information.

Implement subsequent requests

We first create a followup request method named followup_request. Within the followup_request method, read the reviewer.json file and save the contents in a list. code show as below:

with open('reviewer.json','r') as jfile:
    review_info = json.load(jfile)

Next, extract the email information using the read_email method you implemented in the previous tutorial.

email_info = read_email(no_days)

If the reviewer has responded to the review request, there should be an email with the same subject and the Re: tag in front of it. So, iterate through the list of review messages and compare the review subject to the email subject to see if the reviewer has responded to the request.

for review in review_info:
    review_replied = false
    expected_subject = 'RE: ' + review['subject']
    for email in email_info:
        if expected_subject == email['subject']:
            review_replied = True
            print 'Reviewer has responded'
            break;

As shown in the code above, you iterate over the review_info list and check the review information topic against the email subject to see if the reviewer has replied.

Now, once a reviewer responds to a code review request, you don't need to retain specific review information in the reviewer.json file. Therefore, create a Python method named Delete_Info to delete specific review information from the reviewer.json file. Here's what Delete_Info looks like:

def Delete_Info(info, id):
    for i in xrange(len(info)):
        if info[i]['id'] == id:
            info.pop(i)
            break
    return info

As shown in the code above, you have iterated through the list of review information and deleted entries matching the Id. After removing the information from the file, return to the list.

When replying to a comment message, you need to call the Delete_Info method. When calling the Delete_Info method, you need to pass a copy of review_info so as not to alter the original list of information. You will need the original review information list for later comparison. So import the copy Python module to create a copy of the original list of comment messages.

from copy import copy

Create a copy of the review_info list.

review_info_copy = copy(review_info)

When deleting the replied comment information from the original list, pass the copied list to the Delete_Info method.

review_info_copy = Delete_Info(review_info_copy,review['id'])

This is followup_request Method:

def followup_request():
    with open('reviewer.json','r') as jfile:
        review_info = json.load(jfile)
    review_info_copy = copy(review_info)

    email_info = read_email(no_days)

    for review in review_info:
        review_replied = False
        expected_subject = 'Re: ' + review['subject']
        for email in email_info:
            if expected_subject == email['Subject']:
                review_replied = True
                review_info_copy = Delete_Info(review_info_copy,review['id'])
                break;

Now, once the review_info list is iterated, you need to check if there are any changes in the reviewer.json file. If any existing review information has been removed, you will need to update the reviewer.json file accordingly. So, check if review_info_copy and review_info are the same and update the reviewer.json file.

if review_info_copy != review_info:
    with open('reviewer.json','w') as outfile:
        json.dump(review_info_copy,outfile)

This is the complete followup_request Method:

def followup_request():
    with open('reviewer.json','r') as jfile:
        review_info = json.load(jfile)
    review_info_copy = copy(review_info)

    email_info = read_email(no_days)

    for review in review_info:
        review_replied = False
        expected_subject = 'Re: ' + review['subject']
        for email in email_info:
            if expected_subject == email['Subject']:
                review_replied = True
                review_info_copy = Delete_Info(review_info_copy,review['id'])
                break;

    if review_info_copy != review_info:
        with open('reviewer.json','w') as outfile:
            json.dump(review_info_copy,outfile)

Call the followup_request method to follow up the audit request that has been sent.

try:
    commits = process_commits()

    # Added the follow Up Method
    followup_request()

    if len(commits) == 0:
        print 'No commits found '
    else:
        schedule_review_request(commits)

except Exception,e:
    print 'Error occurred. Check log for details.'
    logger.error(str(datetime.datetime.now()) + " - Error occurred : " + str(e) + "\n")
    logger.exception(str(e))

Save the above changes. In order to test subsequent functionality, please delete the reviewer.json file from the project directory. Now run the scheduler to send code review requests to random developers. Check that this information has been saved in the reviewer.json file.

Require specific developers to respond to code review requests by replying to an email. Now run the scheduler again and this time the scheduler should be able to find the response and remove it from the reviewer.json file.

发送提醒电子邮件

审核者回复代码审核请求电子邮件后,需要从 reviewer.json 文件中删除该信息,因为您不需要进一步跟踪它。如果审核者尚未回复代码审核请求,您需要发送后续邮件提醒他或她审核请求。

代码审查调度程序将每天运行。当它运行时,您首先需要检查开发人员响应审核请求是否已经过去了一定时间。在项目配置中,您可以设置一个审核周期,在此期间,如果审核者没有回复,调度程序将发送提醒电子邮件。

让我们首先在项目配置中添加配置。在配置文件中添加一个名为 followup_Frequency 的新配置。

{
    "name": "project_x",
    "git_url": "https://github.com/royagasthyan/project_x",
    "followup_frequency":2,
    "members": [
        "royagasthyan@gmail.com",
    	"samon@gmail.com",
    	"sualonni@gmail.com",
    	"restuni@gmail.com"
    ]
}

因此,当审阅者在 followup_Frequency 天数内没有回复时,您将发送一封提醒电子邮件。读取配置的同时将配置读入全局变量:

for p in main_config:
    if p['name'] == project:
        project_url = p['git_url']
        project_members = p['members']
        followup_frequency = p['followup_frequency']
    break

followup_request 方法内部,当审稿人在 followup_frequest 天数内没有回复后续请求时,发送提醒邮件。计算自评论发送以来的天数。

review_date = datetime.datetime.strptime(review['sendDate'],'%Y-%m-%d')
today = datetime.datetime.today()
days_since_review = (today - review_date).days

如果天数大于配置中的后续频率日期,请发送提醒电子邮件。

if not review_replied:
    if days_since_review > followup_frequency:
        send_email(review['reviewer'],'Reminder: ' + review['subject'],'\nYou have not responded to the review request\n')

这是完整的 followup_request 方法:

def followup_request():
    with open('reviewer.json','r') as jfile:
        review_info = json.load(jfile)
    review_info_copy = copy(review_info)

    email_info = read_email(no_days)

    for review in review_info:
        review_date = datetime.datetime.strptime(review['sendDate'],'%Y-%m-%d')
        today = datetime.datetime.today()
        days_since_review = (today - review_date).days
        review_replied = False
        expected_subject = 'Re: ' + review['subject']
        for email in email_info:
            if expected_subject == email['Subject']:
                review_replied = True
                review_info_copy = Delete_Info(review_info_copy,review['id'])
                break;

        if not review_replied:
            if days_since_review > followup_frequency:
                send_email(review['reviewer'],'Reminder: ' + review['subject'],'\nYou have not responded to the review request\n')

    if review_info_copy != review_info:
        with open('reviewer.json','w') as outfile:
            json.dump(review_info_copy,outfile)

总结

在本教程中,您了解了如何实现跟进代码审核请求的逻辑。您还添加了如果审阅者在一定天数内没有回复电子邮件的情况下发送提醒电子邮件的功能。

这个 Python 代码审查器可以进一步增强以满足您的需求。请分叉存储库并添加新功能,并在下面的评论中告诉我们。

本教程的源代码可在 GitHub 上获取。

The above is the detailed content of Building a Python code review scheduler: review follow-up. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Main Purpose of Python: Flexibility and Ease of UseThe Main Purpose of Python: Flexibility and Ease of UseApr 17, 2025 am 12:14 AM

Python's flexibility is reflected in multi-paradigm support and dynamic type systems, while ease of use comes from a simple syntax and rich standard library. 1. Flexibility: Supports object-oriented, functional and procedural programming, and dynamic type systems improve development efficiency. 2. Ease of use: The grammar is close to natural language, the standard library covers a wide range of functions, and simplifies the development process.

Python: The Power of Versatile ProgrammingPython: The Power of Versatile ProgrammingApr 17, 2025 am 12:09 AM

Python is highly favored for its simplicity and power, suitable for all needs from beginners to advanced developers. Its versatility is reflected in: 1) Easy to learn and use, simple syntax; 2) Rich libraries and frameworks, such as NumPy, Pandas, etc.; 3) Cross-platform support, which can be run on a variety of operating systems; 4) Suitable for scripting and automation tasks to improve work efficiency.

Learning Python in 2 Hours a Day: A Practical GuideLearning Python in 2 Hours a Day: A Practical GuideApr 17, 2025 am 12:05 AM

Yes, learn Python in two hours a day. 1. Develop a reasonable study plan, 2. Select the right learning resources, 3. Consolidate the knowledge learned through practice. These steps can help you master Python in a short time.

Python vs. C  : Pros and Cons for DevelopersPython vs. C : Pros and Cons for DevelopersApr 17, 2025 am 12:04 AM

Python is suitable for rapid development and data processing, while C is suitable for high performance and underlying control. 1) Python is easy to use, with concise syntax, and is suitable for data science and web development. 2) C has high performance and accurate control, and is often used in gaming and system programming.

Python: Time Commitment and Learning PacePython: Time Commitment and Learning PaceApr 17, 2025 am 12:03 AM

The time required to learn Python varies from person to person, mainly influenced by previous programming experience, learning motivation, learning resources and methods, and learning rhythm. Set realistic learning goals and learn best through practical projects.

Python: Automation, Scripting, and Task ManagementPython: Automation, Scripting, and Task ManagementApr 16, 2025 am 12:14 AM

Python excels in automation, scripting, and task management. 1) Automation: File backup is realized through standard libraries such as os and shutil. 2) Script writing: Use the psutil library to monitor system resources. 3) Task management: Use the schedule library to schedule tasks. Python's ease of use and rich library support makes it the preferred tool in these areas.

Python and Time: Making the Most of Your Study TimePython and Time: Making the Most of Your Study TimeApr 14, 2025 am 12:02 AM

To maximize the efficiency of learning Python in a limited time, you can use Python's datetime, time, and schedule modules. 1. The datetime module is used to record and plan learning time. 2. The time module helps to set study and rest time. 3. The schedule module automatically arranges weekly learning tasks.

Python: Games, GUIs, and MorePython: Games, GUIs, and MoreApr 13, 2025 am 12:14 AM

Python excels in gaming and GUI development. 1) Game development uses Pygame, providing drawing, audio and other functions, which are suitable for creating 2D games. 2) GUI development can choose Tkinter or PyQt. Tkinter is simple and easy to use, PyQt has rich functions and is suitable for professional development.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools