Last active
July 16, 2018 20:12
-
-
Save charlesreid1/853735dd9853c00878f8573aa89f656f to your computer and use it in GitHub Desktop.
For a given github repository, create a markdown table of issues+links, and add it to the repo's docs/issues_table folder
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 | |
""" | |
Make Issues Table | |
This script takes the name of a DCPPC workshop repository as an input. | |
It then compiles a list of open issues, and creates a Markdown document | |
containing a table with one column (issue name) that links to the issue. | |
This Markdown document is added to the docs/ folder of the repository. | |
""" | |
# ----------------------------------- | |
# | |
# USER SHOULD CHANGE THESE PARAMETERS | |
# | |
which_repo = "2018-june-workshop" | |
page_title = "June 2018 DCPPC Workshop" | |
page_tagline = "Agenda Items" | |
dry_run = True # Set this to False when you're ok with the table | |
# | |
# ----------------------------------- | |
def main(): | |
make_issues_table() | |
def make_issues_table(): | |
which_org = "dcppc" | |
access_token = os.environ['GITHUB_TOKEN'] | |
# Github -> get organization -> get repository | |
g = Github(access_token) | |
org = g.get_organization(which_org) | |
repo = org.get_repo(which_repo) | |
# Get a list of issues | |
# (this is where you would apply filters using labels, etc) | |
# (to filter by label, need to use Label objects) | |
issues = repo.get_issues() | |
# Create a data container for table data | |
data_for_table = [] | |
page_table = """ | |
| Github Issue Links | | |
| ------------------ | | |
""" | |
for issue in issues: | |
# Assemble table row | |
table_row = "| " | |
table_row += "[{title}]({url})".format( | |
title = issue.title, | |
url = issue.url | |
) | |
table_row += " |\n" | |
# Add row to table | |
page_table += table_row | |
page_body_md = """--- | |
layout: page | |
title: {page_title} | |
tagline: {page_tagline} | |
--- | |
{page_table} | |
""".format( | |
page_title = page_title, | |
page_tagline = page_tagline, | |
page_table = page_table | |
) | |
if(dry_run): | |
print(page_body_md) | |
else: | |
result = repo.create_file( | |
branch = 'test-branch', | |
path = '/docs/issues_table.md', | |
message = 'Adding page with table containing issues links', | |
content = page_body_md | |
) | |
print("Success!") | |
print("Created new file with commit %s"%(result['commit'].sha)) | |
if __name__=="__main__": | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment