Switch to unified view

a/scripts/test-branches-against-tickets.py b/scripts/test-branches-against-tickets.py
...
...
27
27
28
    git('remote prune origin')
28
    git('remote prune origin')
29
29
30
    branches_for_tickets = dict() # maps ticket numbers to the actual branch e.g., int(42) -> 'origin/rc/42'
30
    branches_for_tickets = dict() # maps ticket numbers to the actual branch e.g., int(42) -> 'origin/rc/42'
31
    ticket_nums = dict() # maps ticket numbers to 'merged' or 'unmerged' according to the matching branch
31
    ticket_nums = dict() # maps ticket numbers to 'merged' or 'unmerged' according to the matching branch
32
    commit_diffs = dict() # maps ticket numbers to differences in (number of) commit messages
32
33
33
    merged_branches = [ branch[2:] for branch in git('branch -r --merged dev') if re_ticket_branch.match(branch) ]
34
    merged_branches = [ branch[2:] for branch in git('branch -r --merged dev') if re_ticket_branch.match(branch) ]
34
    unmerged_branches = [ branch[2:] for branch in git('branch -r --no-merged dev') if re_ticket_branch.match(branch) ]
35
    unmerged_branches = [ branch[2:] for branch in git('branch -r --no-merged dev') if re_ticket_branch.match(branch) ]
35
36
36
    for branch in merged_branches:
37
    for branch in merged_branches:
...
...
44
        tn = int(re_ticket_branch.match(branch).group(1))
45
        tn = int(re_ticket_branch.match(branch).group(1))
45
        branches_for_tickets[tn] = branch
46
        branches_for_tickets[tn] = branch
46
        if commits.find('+') == -1:
47
        if commits.find('+') == -1:
47
            ticket_nums[tn] = 'merged'
48
            ticket_nums[tn] = 'merged'
48
        else:
49
        else:
49
            # count the number of commits on this branch
50
            branch_commits = len(git('log --oneline dev..%s' % branch))
50
            branch_commits = git('log --oneline dev..%s' % branch)
51
            # count the number of commits on dev since this branch that contain the ticket #
51
            # count the number of commits on dev since this branch that contain the ticket #
52
            merge_base = git('merge-base', 'dev', branch)[0]
52
            merge_base = git('merge-base', 'dev', branch)[0]
53
            matching_dev_commits = len(git('log --oneline --grep="\[#%s\]" %s..dev' % (tn, merge_base)))
53
            matching_dev_commits = git('log --oneline --grep="\[#%s\]" %s..dev' % (tn, merge_base))
54
54
55
            ticket_nums[tn] = 'merged' if matching_dev_commits >= branch_commits else 'unmerged'
55
            if len(matching_dev_commits) >= len(branch_commits):
56
                ticket_nums[tn] = 'merged'
57
            else:
58
                ticket_nums[tn] = 'unmerged'
59
                commit_diffs[tn] = '\t' + '\n\t'.join(['Branch has:'] + branch_commits +
60
                                                 ['Dev has:'] + matching_dev_commits)
56
61
57
    failure = False
62
    failure = False
58
63
59
    CP.read(os.path.join(os.environ['HOME'], '.forgepushrc'))
64
    CP.read(os.path.join(os.environ['HOME'], '.forgepushrc'))
60
    oauth_client = make_oauth_client()
65
    oauth_client = make_oauth_client()
...
...
65
        if resp[0]['status'] != '200':
70
        if resp[0]['status'] != '200':
66
            continue
71
            continue
67
        ticket = json.loads(resp[1])['ticket']
72
        ticket = json.loads(resp[1])['ticket']
68
        if ticket is None:
73
        if ticket is None:
69
            continue
74
            continue
70
        is_closed = ticket['status'] in ('closed', 'validation')
75
        is_closed = ticket['status'] in ('closed', 'validation', 'wont-fix', 'invalid')
71
        is_merged = ticket_nums[tn] == 'merged'
76
        is_merged = ticket_nums[tn] == 'merged'
72
77
73
        if is_closed != is_merged:
78
        if is_closed != is_merged:
74
            print('<http://sourceforge.net/p/allura/tickets/%s/> is status:"%s", but the branch "%s" is %s' % (tn, ticket['status'], branches_for_tickets[tn], ticket_nums[tn]))
79
            print('<http://sourceforge.net/p/allura/tickets/%s/> is status:"%s", but the branch "%s" is %s' % (tn, ticket['status'], branches_for_tickets[tn], ticket_nums[tn]))
80
            if tn in commit_diffs:
81
                print(commit_diffs[tn])
75
            failure = True
82
            failure = True
76
83
77
    os.chdir(here)
84
    os.chdir(here)
78
    if failure:
85
    if failure:
79
        sys.exit(1)
86
        sys.exit(1)