Created
April 17, 2020 11:22
-
-
Save jordimassaguerpla/8c2f946bbb0039a761e53f9904962cbd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from github import Github | |
import os, sys | |
import yaml | |
# TOOD: this vars should come from the command line | |
github_token = os.environ["GITHUB_TOKEN"] | |
username = os.environ("GITHUB_USERNAME"] | |
release_file = "release.yaml" | |
release_project = "test_release" | |
repo_name = "testing-stuff" | |
g = Github(github_token) | |
with open("release.yaml") as r_file: | |
data = yaml.safe_load(r_file) | |
if (not "release" in data.keys()): | |
print(release_file + " does not contain release") | |
sys.exit(-1) | |
column_name = data["release"] | |
if (not "patch" in data.keys()): | |
print(release_file + "does not contain patch") | |
sys.exit(-2) | |
if ("features" in data["patch"].keys()): | |
content = data["patch"]["features"] | |
if ("issues" in data["patch"].keys()): | |
fixes = "Fixes" | |
for fix in sorted(data["patch"]["issues"]): | |
fixes += " \n* " + fix | |
gh_issues = "Github issues:\n https://github.com/jordimassaguerpla/issues/label=" + column_name | |
content = content + [fixes, gh_issues] | |
g = Github(username, github_token) | |
for proj in g.get_user().get_repo(repo_name).get_projects(): | |
if (proj.name == release_project): | |
print("Project found") | |
release = None | |
for col in proj.get_columns(): | |
if (col.name == column_name): | |
print("Colum found. Not creating column") | |
# removing the column is not working in PyGithub ?? | |
# if we do not remove it, there could be left overs | |
# for example, when removing a feature from a release | |
release = col | |
break | |
if (not release): | |
print("Creating column") | |
release = proj.create_column(column_name) | |
print("Checking for cards") | |
for c in content: | |
found = False | |
for card in release.get_cards(): | |
if (card.note == c): | |
# if (card.id == issue_id): | |
print("Found card. Not creating card") | |
found = True | |
break | |
if (not found): | |
print("Creating card") | |
# using an issues seems broken in the PyGithub | |
# card = release.create_card(content_id=6, content_type="PullRequest") | |
release.create_card(note=c) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment