Skip to content

Commit

Permalink
Check downstreams to make sure that there aren't any unmerged. (#1315)
Browse files Browse the repository at this point in the history
Merged PR #1315.
  • Loading branch information
nat-henderson authored and modular-magician committed Jan 29, 2019
1 parent 6e74928 commit 061bad3
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .ci/ci.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,10 @@ jobs:
plan:
- get: mm-approved-prs
attempts: 2
- task: ensure-downstreams-merged
file: mm-approved-prs/.ci/magic-modules/ensure-downstreams-merged.yml
params:
GH_TOKEN: ((github-account.password))
- put: mark-automerged
resource: mm-approved-prs
params:
Expand Down
24 changes: 24 additions & 0 deletions .ci/magic-modules/ensure-downstreams-merged.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
# This file takes in only magic-modules, to get the code that
# it runs. It does need the github API token.
# It produces no output.
platform: linux

image_resource:
type: docker-image
source:
# This task requires a container with python and the pip
# package 'pygithub'.
repository: gcr.io/magic-modules/python
tag: '1.0'

inputs:
- name: mm-approved-prs

params:
GH_TOKEN: ""

run:
path: mm-approved-prs/.ci/magic-modules/ensure_downstreams_merged.py
args:
- mm-approved-prs/.git/id
36 changes: 36 additions & 0 deletions .ci/magic-modules/ensure_downstreams_merged.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python

import get_downstream_prs
from github import Github
import os
import re
import operator
import itertools
import sys


def get_unmerged_prs(g, dependencies):
parsed_dependencies = [re.match(r'https://github.com/([\w-]+/[\w-]+)/pull/(\d+)', d).groups()
for d in dependencies]
parsed_dependencies.sort(key=operator.itemgetter(0))
unmerged_dependencies = []
# group those dependencies by repo - e.g. [("terraform-provider-google", ["123", "456"]), ...]
for r, pulls in itertools.groupby(parsed_dependencies, key=operator.itemgetter(0)):
repo = g.get_repo(r)
for pull in pulls:
# check whether the PR is merged - if it is, add it to the list.
pr = repo.get_pull(int(pull[1]))
if not pr.is_merged():
unmerged_dependencies.append(pull)
return unmerged_dependencies


if __name__ == '__main__':
g = Github(os.environ.get('GH_TOKEN'))
assert len(sys.argv) == 2
id_filename = sys.argv[1]
unmerged = get_unmerged_prs(
g, get_downstream_prs.get_github_dependencies(
g, int(open(id_filename).read())))
if unmerged:
raise ValueError("some PRs are unmerged", unmerged)
Empty file modified .ci/magic-modules/welcome-contributor.sh
100644 → 100755
Empty file.

0 comments on commit 061bad3

Please sign in to comment.