Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jm1021 committed May 15, 2024
2 parents 8db68e4 + e16c246 commit dfc225b
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions scripts/pull_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import json


def generate_markdown_file(issue_data, file_path):
def generate_markdown_file(issue_data, file_path, course):
"""
Generate a Markdown file for a GitHub issue.
Expand All @@ -21,9 +21,9 @@ def generate_markdown_file(issue_data, file_path):
file.write('layout: post\n') # Adjust layout as needed

file.write('tags: [github, issue]\n') # Add relevant tags
file.write("courses: {'csa': {'week': " + str(issue_data['week']) + "}}\n")
file.write("type: issues\n")
file.write("description: Automatically Populated Github Issue\n")
file.write("courses: {'"+ course + "': {'week': " + str(issue_data['week']) + "}}\n")
file.write("type : issues\n")
file.write("description : Automatically Populated Github Issue\n")
file.write('---\n\n')
# Write issue body
file.write(issue_data['body'] + '\n\n')
Expand All @@ -44,7 +44,7 @@ def get_github_repository_issues(token=None):
query = """
query {
organization(login: "nighthawkcoders") {
projectsV2(first: 1) {
projectsV2(first: 2) {
nodes {
items(first: 100) {
nodes {
Expand Down Expand Up @@ -101,12 +101,13 @@ def create_issues():
# extract the GitHub API token from the secrets in AWS Secrets Manager
token = getToken()["GithubApi"]


# Call the function to get the issues data, then extract a nested data structure from the response, this corresonds to an array of issues
# we need to extract the specific project data, perhaps "projectsV2" in the code to yml file, so we can run CSP and CSSE with same python script
issues_data = get_github_repository_issues(token)["data"]["organization"]["projectsV2"]["nodes"][0]["items"]["nodes"]
csa_data = get_github_repository_issues(token)["data"]["organization"]["projectsV2"]["nodes"][0]["items"]["nodes"]
# we need to move the data logic into yml file in order to have accurate week calculation
date1 = datetime(2023, 8, 21)
for issue in issues_data:
for issue in csa_data:
issue = issue["content"]
if issue:
dueDate = issue["projectItems"]["nodes"][0]["fieldValues"]["nodes"][4]["date"]
Expand All @@ -120,7 +121,27 @@ def create_issues():
'created_at': issue["createdAt"][:10],
'week': math.floor(week - 3)
}
generate_markdown_file(issue_data, f"_posts/{dueDate}-{issue['title'].replace(' ', '-').replace('/', ' ')}_GithubIssue_.md")
generate_markdown_file(issue_data, f"_posts/{dueDate}-{issue['title'].replace(' ', '-').replace('/', ' ')}_GithubIssue_.md", "csa")

# Recieves the CSP data through searching the second project entry rather than the first
csp_data = get_github_repository_issues(token)["data"]["organization"]["projectsV2"]["nodes"][1]["items"]["nodes"]
date1 = datetime(2023, 8, 21)
for issue in csp_data:
issue = issue["content"]
if issue:
dueDate = issue["projectItems"]["nodes"][0]["fieldValues"]["nodes"][4]["date"]
year, month, day = map(int, dueDate.split("-"))
date2 = datetime(year,month,day)
difference = date2 - date1
week = difference.days/7
issue_data = {
'title': issue["title"],
'body': issue["body"],
'created_at': issue["createdAt"][:10],
'week': math.floor(week - 3)
}
generate_markdown_file(issue_data, f"_posts/{dueDate}-{issue['title'].replace(' ', '-').replace('/', ' ')}_GithubIssue_.md", "csp")


def getToken():
# confirm that this endpoing is storing key that works for all nighthawkcoders repos
Expand Down

0 comments on commit dfc225b

Please sign in to comment.