Esempio n. 1
0
    def insert_pulls(labels=None, state="open", since=None, org=False):
        mongo_client = MongoClient()
        mongo_collection = mongo_client.prs.prs

        issues = get_pulls("edx/edx-platform", labels, state, since, org)
        for issue in issues:
            mongo_collection.insert(issue)
Esempio n. 2
0
    def insert_pulls(labels=None, state="open", since=None, org=False):
        mongo_client = MongoClient()
        mongo_collection = mongo_client.prs.prs

        issues = get_pulls("edx/edx-platform", labels, state, since, org)
        for issue in issues:
            mongo_collection.insert(issue)
Esempio n. 3
0
def show_pulls(labels=None, show_comments=False, state="open", since=None,
               org=False, intext=None, merged=False):
    """
    `labels`: Filters PRs by labels (all are shown if None is specified)
    `show_comments`: shows the last 5 comments on each PR, if True
    `state`: Filter PRs by this state (either 'open' or 'closed')
    `since`: a datetime representing the earliest time from which to pull information.
             All PRs regardless of time are shown if None is specified.
    `org`: If True, sorts by PR author affiliation
    `intext`: specify 'int' (internal) or 'ext' (external) pull request
    `merged`: If True and state="closed", shows only PRs that were merged.
    """
    num = 0
    adds = 0
    deletes = 0
    repos = [ r for r in Repo.from_yaml() if r.track_pulls ]
    for repo in repos:
        issues = get_pulls(repo.name, labels, state, since, org=org or intext, pull_details="all")

        category = None
        for issue in issues:
            issue.repo = repo.nick
            if intext is not None:
                if issue.intext != intext:
                    continue
            if state == 'closed' and merged and issue.combinedstate != 'merged':
                # If we're filtering on closed PRs, and only want those that are merged,
                # skip ones that were closed without merge.
                continue
            if state == 'closed' and since:
                # If this PR was closed prior to the last `since` interval of days, continue on
                # (it may have been *updated* - that is, referenced or commented on - more recently,
                #  but we just want to see what's been merged or closed in the past "since" days)
                if issue.closed_at < since:
                    continue

            if org and issue.org != category:
                # new category! print category header
                category = issue.org
                print("-- {category} ----".format(category=category))

            print(fformat(ISSUE_FMT, issue))
            num += 1
            adds += issue.additions
            deletes += issue.deletions

            if show_comments:
                comments = get_comments(issue)
                last_five_comments = reversed(more_itertools.take(5, comments))
                for comment in last_five_comments:
                    print(fformat(COMMENT_FMT, comment))

    print()
    print("{num} pull requests; {adds}+ {deletes}-".format(num=num, adds=adds, deletes=deletes))
Esempio n. 4
0
    def show_pulls(labels=None, show_comments=False, state="open", since=None, org=False):
        months = collections.defaultdict(lambda: {'opened': 0, 'merged': 0})
        issues = get_pulls("edx/edx-platform", labels, state, since, org, pull_details="all")
        for issue in issues:
            months[yearmonth(issue['created_at'])]['opened'] += 1
            if issue['pull.merged']:
                months[yearmonth(issue['pull.merged_at'])]['merged'] += 1

        print(months)
        for ym, data in sorted(months.items()):
            print("{ym},{data[opened]},{data[merged]}".format(ym=ym, data=data))
Esempio n. 5
0
 def one_repo(self, repo):
     issues = get_pulls(repo.name, state="open", org=True, pull_details="list")
     for issue in issues:
         issue.repo = repo.nick
         for label in issue.labels:
             if label in self.team_names:
                 self.add_pull(issue)
                 break
         else:
             # Didn't find a blocking label, include it if external.
             if issue.intext == "external":
                 self.add_pull(issue)
Esempio n. 6
0
 def one_repo(self, repo):
     issues = get_pulls(repo.name,
                        state="open",
                        org=True,
                        pull_details="list")
     for issue in issues:
         issue.repo = repo.nick
         for label in issue.labels:
             if label in self.team_names:
                 self.add_pull(issue)
                 break
         else:
             # Didn't find a blocking label, include it if external.
             if issue.intext == "external":
                 self.add_pull(issue)
Esempio n. 7
0
    def show_pulls(labels=None,
                   show_comments=False,
                   state="open",
                   since=None,
                   org=False):
        months = collections.defaultdict(lambda: {'opened': 0, 'merged': 0})
        issues = get_pulls("edx/edx-platform",
                           labels,
                           state,
                           since,
                           org,
                           pull_details="all")
        for issue in issues:
            months[yearmonth(issue['created_at'])]['opened'] += 1
            if issue['pull.merged']:
                months[yearmonth(issue['pull.merged_at'])]['merged'] += 1

        print(months)
        for ym, data in sorted(months.items()):
            print("{ym},{data[opened]},{data[merged]}".format(ym=ym,
                                                              data=data))
Esempio n. 8
0
def main(argv):
    parser = argparse.ArgumentParser(description="Summarize pull requests by organization.")
    parser.add_argument(
        "--since", metavar="DAYS", type=int,
        help="Only consider pull requests closed in the past DAYS days"
    )
    parser.add_argument(
        "--start", type=date_arg,
        help="Date to start collecting, format is flexible: "
        "20141225, Dec/25/2014, 2014-12-25, etc"
    )
    parser.add_argument(
        "--end", type=date_arg,
        help="Date to end collecting, format is flexible: "
        "25/Dec/2014, 12/25/2014, 2014-12-25, etc"
    )
    parser.add_argument(
        "--short", action="store_true",
        help="Only show the short summary"
    )

    args = parser.parse_args(argv[1:])

    since = None
    if args.since:
        since = make_timezone_aware(datetime.today() - timedelta(days=args.since))
    if args.start:
        if since is not None:
            raise Exception("Can't use --since and --start")
        since = args.start

    repos = [ r for r in Repo.from_yaml() if r.track_pulls ]

    by_org = collections.defaultdict(list)

    for repo in repos:
        for pull in get_pulls(repo.name, state="closed", pull_details="list", org=True, since=since):
            # We only want external pull requests.
            if pull.intext != "external":
                continue
            # We only want merged pull requests.
            if pull.combinedstate != "merged":
                continue
            # Pull requests can be recently modified even if they were merged
            # long ago, so only take things merged since our since date.
            merged = make_timezone_aware(pull.merged_at)
            if merged < since:
                continue

            if args.end is not None:
                # We don't want to count things merged after our end date.
                if merged >= args.end:
                    continue

            pull.repo = repo.nick
            by_org[pull.org].append(pull)

    keys = sorted(by_org, key=lambda k: len(by_org[k]), reverse=True)
    for key in keys:
        print("{}: {}".format(key, len(by_org[key])))

    fmt = "{pull.repo:4s} {pull.number:5d} {pull.user_login:>17s} {pull.title}"

    if args.short:
        if 'unsigned' in keys:
            print("\n-- {} -------".format('unsigned'))
            for pull in by_org['unsigned']:
                print(fmt.format(pull=pull))
    else:
        for key in keys:
            print("\n-- {} -------".format(key))
            for pull in by_org[key]:
                print(fmt.format(pull=pull))
Esempio n. 9
0
def show_pulls(labels=None,
               show_comments=False,
               state="open",
               since=None,
               org=False,
               intext=None,
               merged=False):
    """
    `labels`: Filters PRs by labels (all are shown if None is specified)
    `show_comments`: shows the last 5 comments on each PR, if True
    `state`: Filter PRs by this state (either 'open' or 'closed')
    `since`: a datetime representing the earliest time from which to pull information.
             All PRs regardless of time are shown if None is specified.
    `org`: If True, sorts by PR author affiliation
    `intext`: specify 'int' (internal) or 'ext' (external) pull request
    `merged`: If True and state="closed", shows only PRs that were merged.
    """
    num = 0
    adds = 0
    deletes = 0
    repos = [r for r in Repo.from_yaml() if r.track_pulls]
    for repo in repos:
        issues = get_pulls(repo.name,
                           labels,
                           state,
                           since,
                           org=org or intext,
                           pull_details="all")

        category = None
        for issue in issues:
            issue.repo = repo.nick
            if intext is not None:
                if issue.intext != intext:
                    continue
            if state == 'closed' and merged and issue.combinedstate != 'merged':
                # If we're filtering on closed PRs, and only want those that are merged,
                # skip ones that were closed without merge.
                continue
            if state == 'closed' and since:
                # If this PR was closed prior to the last `since` interval of days, continue on
                # (it may have been *updated* - that is, referenced or commented on - more recently,
                #  but we just want to see what's been merged or closed in the past "since" days)
                if issue.closed_at < since:
                    continue

            if org and issue.org != category:
                # new category! print category header
                category = issue.org
                print("-- {category} ----".format(category=category))

            print(fformat(ISSUE_FMT, issue))
            num += 1
            adds += issue.additions
            deletes += issue.deletions

            if show_comments:
                comments = get_comments(issue)
                last_five_comments = reversed(more_itertools.take(5, comments))
                for comment in last_five_comments:
                    print(fformat(COMMENT_FMT, comment))

    print()
    print("{num} pull requests; {adds}+ {deletes}-".format(num=num,
                                                           adds=adds,
                                                           deletes=deletes))
Esempio n. 10
0
def main(argv):
    parser = argparse.ArgumentParser(
        description="Summarize pull requests by organization.")
    parser.add_argument(
        "--since",
        metavar="DAYS",
        type=int,
        help="Only consider pull requests closed in the past DAYS days")
    parser.add_argument("--start",
                        type=date_arg,
                        help="Date to start collecting, format is flexible: "
                        "20141225, Dec/25/2014, 2014-12-25, etc")
    parser.add_argument("--end",
                        type=date_arg,
                        help="Date to end collecting, format is flexible: "
                        "25/Dec/2014, 12/25/2014, 2014-12-25, etc")
    parser.add_argument("--short",
                        action="store_true",
                        help="Only show the short summary")

    args = parser.parse_args(argv[1:])

    since = None
    if args.since:
        since = make_timezone_aware(datetime.today() -
                                    timedelta(days=args.since))
    if args.start:
        if since is not None:
            raise Exception("Can't use --since and --start")
        since = args.start

    repos = [r for r in Repo.from_yaml() if r.track_pulls]

    by_org = collections.defaultdict(list)

    for repo in repos:
        for pull in get_pulls(repo.name,
                              state="closed",
                              pull_details="list",
                              org=True,
                              since=since):
            # We only want external pull requests.
            if pull.intext != "external":
                continue
            # We only want merged pull requests.
            if pull.combinedstate != "merged":
                continue
            # Pull requests can be recently modified even if they were merged
            # long ago, so only take things merged since our since date.
            merged = make_timezone_aware(pull.merged_at)
            if merged < since:
                continue

            if args.end is not None:
                # We don't want to count things merged after our end date.
                if merged >= args.end:
                    continue

            pull.repo = repo.nick
            by_org[pull.org].append(pull)

    keys = sorted(by_org, key=lambda k: len(by_org[k]), reverse=True)
    for key in keys:
        print("{}: {}".format(key, len(by_org[key])))

    fmt = "{pull.repo:4s} {pull.number:5d} {pull.user_login:>17s} {pull.title}"

    if args.short:
        if 'unsigned' in keys:
            print("\n-- {} -------".format('unsigned'))
            for pull in by_org['unsigned']:
                print(fmt.format(pull=pull))
    else:
        for key in keys:
            print("\n-- {} -------".format(key))
            for pull in by_org[key]:
                print(fmt.format(pull=pull))