Exemplo n.º 1
0
async def showissuedependencies(gh, issue_url) -> bool:

    # Get the issue number and its associated database info
    issue_number = int(issue_url[issue_url.rindex("/") + 1 :])
    issue_db_info = dynamodb.getIssue(issue_number)

    # Do nothing if the current issue is not initialized in the database.
    # Notify the user that they must initialize the current issue.
    if issue_db_info is None:
        # Replace the url to say "issues" if "pulls" exists
        issue_url = issue_url.replace("/pulls/", "/issues/")

        await gh.post(
            issue_url + "/comments",
            data={
                "body": "Command failed. Please first initialize the repository by using `@bot-name init` and then try again."
            },
        )
        return False

    # Format parent issue.
    if issue_db_info["parent_issue"] > 0:
        parent_issue_info = "**Parent Issue:** #" + str(issue_db_info["parent_issue"])
    else:
        parent_issue_info = "**Parent Issue:** None."

    # Format child issues.
    child_issue_info = "**Child Issues:**"
    if len(issue_db_info["child_issues"]) > 0:
        is_first = True
        for child_issue in issue_db_info["child_issues"]:
            if not is_first:
                child_issue_info = child_issue_info + ","
            else:
                is_first = False

            child_issue_info = child_issue_info + " #" + str(child_issue)
    else:
        child_issue_info = child_issue_info + " None."

    # Replace the url to say "issues" if "pulls" exists
    issue_url = issue_url.replace("/pulls/", "/issues/")

    await gh.post(
        issue_url + "/comments",
        data={
            "body": "These are the issue dependencies for this issue:\n\n"
            + parent_issue_info
            + "\n\n"
            + child_issue_info
        },
    )
    return True
Exemplo n.º 2
0
async def showreviewers(gh, issue_url) -> bool:

    # Get the issue number and its associated database info
    issue_number = int(issue_url[issue_url.rindex("/") + 1 :])
    issue_db_info = dynamodb.getIssue(issue_number)

    # Do nothing if the current issue is not initialized in the database.
    # Notify the user that they must initialize the current issue.
    if issue_db_info is None:
        # Replace the url to say "issues" if "pulls" exists
        issue_url = issue_url.replace("/pulls/", "/issues/")

        await gh.post(
            issue_url + "/comments",
            data={
                "body": "Command failed. Please first initialize the repository by using `@bot-name init` and then try again."
            },
        )
        return False

    # Obtain information for reviewers in this pull request.
    reviewers = []
    for reviewer in issue_db_info["reviewers"]:
        reviewer_db_info = dynamodb.getReviewer(reviewer, issue_number)
        reviewers.append(reviewer_db_info)

    # Format reviewer information into a Markdown table.
    reviewer_info = "\n\nUsername | Role | Description\n--- | --- | ---"
    for reviewer in reviewers:
        reviewer_info = (
            reviewer_info
            + "\n"
            + reviewer["github_username"]
            + " | "
            + reviewer["role"]
            + " | "
            + reviewer["role_description"]
        )

    # Replace the url to say "issues" if "pulls" exists
    issue_url = issue_url.replace("/pulls/", "/issues/")

    await gh.post(
        issue_url + "/comments",
        data={
            "body": "These are the reviewers for this issue along with their role and a description for their role:"
            + reviewer_info
        },
    )
    return True
Exemplo n.º 3
0
async def documentationDefect(comment_data, args, issue_url):
    defect_count = dynamodb.getDefectCount()
    defect = dict()
    if len(args) > 8:  # if the input line is multi line
        line_num = [i for i in range(int(args[4]), int(args[6]) + 1)]
        endline_num = -1 - (
            (int(args[6]) + 1) -
            (int(args[4]) + 1))  # calculate the end of the selected line
        code_seg = [(comment_data["diff_hunk"].split("\n")[x])[1:]
                    for x in range(-1, endline_num - 1, -1)]
        code_seg = code_seg[::-1]
        defect.update({
            "defect_number": int(defect_count),
            "file_name": comment_data["path"],
            "description": args[9],
            "line_numbers": line_num,
            "code_segments": code_seg,
        })
    else:
        line_num = [int(args[4])]  # if the input line is a single line
        code_seg = list(comment_data["diff_hunk"].split("\n"))
        defect.update({
            "defect_number": int(defect_count),
            "file_name": comment_data["path"],
            "description": args[7],
            "line_numbers": line_num,
            "code_segments": [code_seg[-1].replace("+", "")],
        })
    dynamodb.createDefect(defect)

    # Update the documentation_defects field in issue
    issue_number = issue_url.split("/")[-1]
    updatedissue = dict()
    currIssue = dynamodb.getIssue(int(issue_number))
    lgic_num = list()
    for item in currIssue["documentation_defects"]:
        lgic_num.append(int(item))
    lgic_num.append(defect["defect_number"])
    updatedissue.update({"documentation_defects": lgic_num})
    dynamodb.updateIssue(int(issue_number), updatedissue)
Exemplo n.º 4
0
async def init(gh, issue_url):

    # Obtain the issue information from GitHub
    issue = await gh.getitem(issue_url)

    # Check if this issue has been initialized in the database already
    issue_db_data = dynamodb.getIssue(int(issue["number"]))
    if issue_db_data is not None:
        # Replace the url to say "issues" if "pulls" exists
        issue_url = issue_url.replace("/pulls/", "/issues/")

        await gh.post(
            issue_url + "/comments",
            data={
                "body":
                "Command failed. This issue has already been initialized."
            },
        )
        return

    # Give the issue an entry in the database
    dynamodb.createIssue({
        "issue_number": issue["number"],
        "reviewers": [],
        "changed_files": [],
        "parent_issue": -1,
        "child_issues": [],
        "documentation_defects": [],
        "logic_defects": [],
    })

    # Replace the url to say "issues" if "pulls" exists
    issue_url = issue_url.replace("/pulls/", "/issues/")

    # Confirm to the user that the bot has been successfully initialized
    await gh.post(issue_url + "/comments",
                  data={"body": "🤖 The bot has initialized this issue!"})
async def parentissue(gh, issue_url, repo_url, args):
    """
    args:
        arg[2] is the issue number of the parent issue
    """

    if len(args) < 3:
        # Replace the url to say "issues" if "pulls" exists
        issue_url = issue_url.replace("/pulls/", "/issues/")

        await gh.post(
            issue_url + "/comments",
            data={
                "body":
                "Command failed. Please use format `@bot-name parent issue is <parent issue number>`."
            },
        )
        return

    if not args[2].isdigit() or int(args[2]) == 0:
        # Replace the url to say "issues" if "pulls" exists
        issue_url = issue_url.replace("/pulls/", "/issues/")

        await gh.post(
            issue_url + "/comments",
            data={
                "body":
                "Command failed. Please use a positive integer value as input with the format `@bot-name parent issue is <parent issue number>`."
            },
        )
        return

    # Obtain the current issue data and obtain where the old parent issue location is in the main post.
    issue_data = await gh.getitem(issue_url)

    # Make sure the child issue is in the database.
    issue_db_info = dynamodb.getIssue(issue_data["number"])
    if issue_db_info is None:
        # Replace the url to say "issues" if "pulls" exists
        issue_url = issue_url.replace("/pulls/", "/issues/")

        await gh.post(
            issue_url + "/comments",
            data={
                "body":
                "Command failed. Please first initialize this repository by using `@bot-name init` and then try again."
            },
        )
        return

    # Make sure the new parent issue is in the database.
    new_parent_issue_db_info = dynamodb.getIssue(int(args[2]))
    if new_parent_issue_db_info is None:
        # Replace the url to say "issues" if "pulls" exists
        issue_url = issue_url.replace("/pulls/", "/issues/")

        await gh.post(
            issue_url + "/comments",
            data={
                "body":
                "Command failed. Please first initialize the parent repository by using `@bot-name init` in #"
                + args[2] + " and then try again."
            },
        )
        return

    # Obtain the old parent issue's number
    old_parent_issue_number = issue_db_info["parent_issue"]

    # If there is no old parent issue, old_parent_issue_number will be -1
    if old_parent_issue_number > 0:
        # Remove child issue from old parent issue.
        # The database entry should already exist.
        old_parent_issue_db_info = dynamodb.getIssue(old_parent_issue_number)
        old_parent_issue_db_info["child_issues"].remove(issue_data["number"])
        dynamodb.updateIssue(old_parent_issue_number, old_parent_issue_db_info)

    # Add child issue to new parent issue.
    new_parent_issue_db_info["child_issues"].append(issue_data["number"])
    dynamodb.updateIssue(int(args[2]), new_parent_issue_db_info)

    # Add new parent issue to child issue.
    issue_db_info["parent_issue"] = int(args[2])
    dynamodb.updateIssue(issue_data["number"], issue_db_info)

    # Replace the url to say "issues" if "pulls" exists
    issue_url = issue_url.replace("/pulls/", "/issues/")

    await gh.post(
        issue_url + "/comments",
        data={
            "body":
            "The parent issue has been successfully changed to #" + args[2] +
            "."
        },
    )
    return
async def openissue(gh, issue_url, repo_url, args) -> True:
    """
    args:
        arg[3] is the title of the new issue
        arg[6] is the body of the new issue (optional)
    """

    # If the proper arguments aren't passed through, don't compute and notify the user
    if len(args) < 4:
        # Replace the url to say "issues" if "pulls" exists
        issue_url = issue_url.replace("/pulls/", "/issues/")

        await gh.post(
            issue_url + "/comments",
            data={
                "body":
                'Command failed. Please use format `@bot-name open issue with title "<title of new issue>" [and description "<body of new issue>"]`.'
            },
        )
        return False

    # Get the issue number and its associated database info
    curr_issue_number = int(issue_url[issue_url.rindex("/") + 1:])
    issue_db_info = dynamodb.getIssue(curr_issue_number)

    # Do nothing if the current issue is not initialized in the database.
    # Notify the user that they must initialize the current issue.
    if issue_db_info is None:
        # Replace the url to say "issues" if "pulls" exists
        issue_url = issue_url.replace("/pulls/", "/issues/")

        await gh.post(
            issue_url + "/comments",
            data={
                "body":
                "Command failed. Please first initialize the repository by using `@bot-name init` and then try again."
            },
        )
        return False

    # The second argument, the description of the issue, is optional.
    # Add a dummy argument if it does not exist.
    if len(args) < 5:
        body = ""
    else:
        body = args[6]

    # Create the new issue
    child_issue = await gh.post(repo_url + "/issues",
                                data={
                                    "title": args[3],
                                    "body": body
                                })

    # Add the new issue to the database (and essentially initializing it)
    child_issue_db_info = {
        "issue_number": int(child_issue["number"]),
        "reviewers": [],
        "changed_files": [],
        "parent_issue": curr_issue_number,
        "child_issues": [],
        "documentation_defects": [],
        "logic_defects": [],
    }
    dynamodb.createIssue(child_issue_db_info)

    await gh.post(
        child_issue["url"] + "/comments",
        data={"body": "🤖 The bot has initialized this issue!"},
    )

    # Add the new issue to the parent issue's database entry
    issue_db_info["child_issues"].append(child_issue["number"])
    changed_db_info = {"child_issues": issue_db_info["child_issues"]}
    dynamodb.updateIssue(curr_issue_number, changed_db_info)

    # Replace the url to say "issues" if "pulls" exists
    issue_url = issue_url.replace("/pulls/", "/issues/")

    await gh.post(
        issue_url + "/comments",
        data={
            "body":
            "New issue has been successfully created as #" +
            str(child_issue["number"]) + "."
        },
    )

    return True
Exemplo n.º 7
0
async def assign(gh, issue_url, comment_url, args) -> bool:

    # If not a pull request, you cannot assign a reviewer
    if "/issues/" in issue_url:
        # Replace the url to say "issues" if "pulls" exists
        issue_url = issue_url.replace("/pulls/", "/issues/")

        await gh.post(
            issue_url + "/comments",
            data={
                "body": "Command failed. You cannot assign code reviewers to an issue. You can only assign reviewers to pull requests."
            },
        )
        return False

    # If the proper arguments aren't passed through, don't compute and notify the user
    if len(args) < 3:
        # Replace the url to say "issues" if "pulls" exists
        issue_url = issue_url.replace("/pulls/", "/issues/")

        await gh.post(
            issue_url + "/comments",
            data={
                "body": 'Command failed. Please use format `@bot-name assign issue to @user-name with role <role> and description "<description of role>"`.'
            },
        )
        return False

    # Get the issue number and its associated database info
    issue_number = int(issue_url[issue_url.rindex("/") + 1 :])
    issue_db_info = dynamodb.getIssue(issue_number)

    # Do nothing if the current issue is not initialized in the database.
    # Notify the user that they must initialize the current issue.
    if issue_db_info is None:
        # Replace the url to say "issues" if "pulls" exists
        issue_url = issue_url.replace("/pulls/", "/issues/")

        await gh.post(
            issue_url + "/comments",
            data={
                "body": "Command failed. Please first initialize the repository by using `@bot-name init` and then try again."
            },
        )
        return False

    reviewer = args[2][1:]
    role = args[5]
    description = args[8]

    reviewers = issue_db_info["reviewers"]
    reviewers.append(reviewer)
    if role.upper() not in roles:
        # Replace the url to say "issues" if "pulls" exists
        issue_url = issue_url.replace("/pulls/", "/issues/")

        await gh.post(
            issue_url + "/comments",
            data={
                "body": "Command failed. Provided role does not exist. Use the command `@bot-name roles` to see existing roles."
            },
        )
        return False

    """
    The following is how to tell if the message is in the conversation tab or in a file change tab
    """

    # comment_id = comment_url[comment_url.rfind('/') + 1:]
    # parent_comment = issue_url + '/comments/' + comment_id + '/replies'

    # ''' "pulls" in comment_url when commented in file change tab
    # 	"issues" in comment_url when commented in conversation tab, but "pulls" in issue_url'''
    # if "/pulls/" in comment_url:
    # 	await gh.post(parent_comment, data={
    # 		'body': body
    # 	})
    # elif "/issues/" in comment_url:
    # 	new_issue_url = issue_url.replace("/pulls/", "/issues/")
    # 	await gh.post(new_issue_url + '/comments', data={
    # 		'body': body
    # 	})

    # Create an entry for the reviewer information in the database
    dynamodb.createReviewer(
        {
            "github_username": reviewer,
            "issue_number": issue_number,
            "role": role,
            "role_description": description,
        }
    )

    # Update the entry for the issue in the database to include the new reviewer
    issue_db_info["reviewers"] = reviewers
    dynamodb.updateIssue(issue_number, issue_db_info)

    # Request the new reviewer
    await gh.post(issue_url + "/requested_reviewers", data={"reviewers": reviewers})

    # Replace the url to say "issues" if "pulls" exists
    issue_url = issue_url.replace("/pulls/", "/issues/")

    await gh.post(
        issue_url + "/comments", data={"body": "@" + reviewer + " is successfully assigned!"},
    )
    return True