예제 #1
0
def graphNewcomers(repoPath, newcomers):
    # Sometimes we get bad data?
    newcomers = [x for x in newcomers if len(x.split('\t')) >= 4]

    issue = [x for x in newcomers if x.split('\t')[2].startswith('issue')]
    comment = [x for x in newcomers if x.split('\t')[2].startswith('comment')]
    pull = [x for x in newcomers if jsonIsPullRequest(x.split('\t')[2])]
    commentPR = [
        x for x in newcomers if jsonIsPullRequestComment(x.split('\t')[2])
    ]
    # For each line, pull out the filename (third item)
    data = [
        Bar(
            x=[
                'Opened an issue',
                'Commented on an issue<BR>opened by someone else',
                'Opened a pull request',
                'Commented on a pull request<BR>opened by someone else'
            ],
            y=[len(issue), len(comment),
               len(pull), len(commentPR)],
        )
    ]
    layout = Layout(title='First contribution types for<BR>' + repoPath, )
    fig = Figure(data=data, layout=layout)
    return offline.plot(fig,
                        show_link=False,
                        include_plotlyjs=False,
                        output_type='div')
예제 #2
0
def separatePRs(repoPath, username, cutoff):
    interaction = []
    noInteraction = []
    # Save the pr-*.txt filenames where username commented
    # in the comment or pr-comment
    for directory in os.listdir(repoPath):
        if not os.path.isdir(os.path.join(repoPath, directory)):
            continue

        match = False
        files = os.listdir(os.path.join(repoPath, directory))
        prFile = [x for x in files if jsonIsPullRequest(x)]
        if not prFile:
            continue

        # Figure out whether this pull request was merged or not
        with open(os.path.join(repoPath, directory, prFile[0])) as f:
            prSoup = json.load(f)
        if cutoff and datetime.strptime(prSoup['created_at'],
                                        "%Y-%m-%dT%H:%M:%SZ") < cutoff:
            continue

        if not prSoup['merged']:
            merged = 0
            seconds = None
        else:
            merged = 1
            ctime = datetime.strptime(prSoup['created_at'],
                                      "%Y-%m-%dT%H:%M:%SZ")
            mtime = datetime.strptime(prSoup['merged_at'],
                                      "%Y-%m-%dT%H:%M:%SZ")
            seconds = (mtime - ctime).total_seconds()
            if (seconds < 0):
                print("WARN: PR", os.path.join(repoPath, directory, prFile[0]),
                      "merged before it was created?")
                print("Created", ctime)
                print("Merged", mtime)
                seconds = 0

        # Figure out if username made an issue or pr comment
        comments = [
            x for x in files
            if jsonIsPullRequestComment(x) or x.startswith('comment-')
        ]
        for cfile in comments:
            with open(os.path.join(repoPath, directory, cfile)) as commentFile:
                soup = json.load(commentFile)
                user, date = getUserDate(soup)
                if user == username:
                    match = True
        if match:
            interaction.append((os.path.join(repoPath,
                                             directory), merged, seconds))
        else:
            noInteraction.append((os.path.join(repoPath,
                                               directory), merged, seconds))
    return interaction, noInteraction
예제 #3
0
def separateByDate(repoPath, cutoff, startDate, endDate):
    older = []
    newer = []
    for directory in os.listdir(repoPath):
        if not os.path.isdir(os.path.join(repoPath, directory)):
            continue

        match = False
        files = os.listdir(os.path.join(repoPath, directory))
        prFile = [x for x in files if jsonIsPullRequest(x)]
        if not prFile:
            continue

        # Figure out whether this pull request was merged or not
        with open(os.path.join(repoPath, directory, prFile[0])) as f:
            prSoup = json.load(f)

        if not prSoup['merged']:
            merged = 0
            seconds = None
        else:
            merged = 1
            ctime = datetime.strptime(prSoup['created_at'],
                                      "%Y-%m-%dT%H:%M:%SZ")
            mtime = datetime.strptime(prSoup['merged_at'],
                                      "%Y-%m-%dT%H:%M:%SZ")
            seconds = (mtime - ctime).total_seconds()
            if (seconds < 0):
                print("WARN: PR", os.path.join(repoPath, directory, prFile[0]),
                      "merged before it was created?")
                print("Created", ctime)
                print("Merged", mtime)
                seconds = 0
            else:
                # Convert to hours, to make graphs easier to read
                seconds = seconds / (60. * 60)
        if (startDate and ctime < startDate) or (endDate and ctime > endDate):
            continue
        if ctime < cutoff:
            older.append((os.path.join(repoPath, directory), merged, seconds))
        else:
            newer.append((os.path.join(repoPath, directory), merged, seconds))
    return older, newer