Skip to content

Commit

Permalink
add tokens as arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
gmguarino committed Jan 31, 2024
1 parent cdaf032 commit e080a9e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 42 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/dashboard_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ jobs:
run: |
pip install -r requirements.txt
- name: Update Dashboards
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NOTION_TOKEN: ${{ secrets.NOTION_DASHBOARD_TOKEN }}
# env:
# GITHUB_TOKEN: {{ secrets.GITHUB_TOKEN }}
# NOTION_TOKEN: {{ secrets.NOTION_DASHBOARD_TOKEN }}
run: |
python update_dashboards.py --config config/projects.json
python update_dashboards.py \
--config config/projects.json \
--notion-token ${{ secrets.NOTION_DASHBOARD_TOKEN }} \
--github-token ${{ secrets.GITHUB_TOKEN }}
58 changes: 29 additions & 29 deletions dashboards/database_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,32 +203,32 @@ def get_or_create_database(self, template_file, records):



if __name__=="__main__":
# Testing the search API
from dotenv import load_dotenv

load_dotenv("creds.env")

NOTION_TOKEN = os.environ.get("NOTION_TOKEN")
headers = {
"Authorization": "Bearer " + NOTION_TOKEN,
"Content-Type": "application/json",
"Notion-Version": "2022-06-28",
}
data = {
"query":"Repository Activity",
"filter": {
"value": "database",
"property": "object"
},
"sort":{
"direction":"ascending",
"timestamp":"last_edited_time"
}
}

response = requests.post("https://api.notion.com/v1/search", headers=headers, json=data)
for result in response.json()['results']:
if result["parent"]["type"] == "page_id":
if result["parent"]["page_id"] == os.environ.get("PAGE_ID"):
print(result['id'], result["title"][0]["text"]["content"])
# if __name__=="__main__":
# # Testing the search API
# from dotenv import load_dotenv

# load_dotenv("creds.env")

# NOTION_TOKEN = os.environ.get("NOTION_TOKEN")
# headers = {
# "Authorization": "Bearer " + NOTION_TOKEN,
# "Content-Type": "application/json",
# "Notion-Version": "2022-06-28",
# }
# data = {
# "query":"Repository Activity",
# "filter": {
# "value": "database",
# "property": "object"
# },
# "sort":{
# "direction":"ascending",
# "timestamp":"last_edited_time"
# }
# }

# response = requests.post("https://api.notion.com/v1/search", headers=headers, json=data)
# for result in response.json()['results']:
# if result["parent"]["type"] == "page_id":
# if result["parent"]["page_id"] == os.environ.get("PAGE_ID"):
# print(result['id'], result["title"][0]["text"]["content"])
24 changes: 15 additions & 9 deletions update_dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import argparse


NOTION_TOKEN = os.environ.get("NOTION_DASHBOARD_TOKEN")
GITHUB_TOKEN = os.environ.get("GITHUB_TOKEN")
# NOTION_TOKEN = os.environ.get("NOTION_DASHBOARD_TOKEN")
# GITHUB_TOKEN = os.environ.get("GITHUB_TOKEN")

print(os.environ)

Expand All @@ -19,15 +19,16 @@ def get_config(path):
return config


def initialize_overview_dashboard(parent_page_id):
def initialize_overview_dashboard(args, parent_page_id):
start_records = [
{"Event": {"title": [{"type":"text", "text": {"content": "Contributors"}}]}, "Count": {"number": 0}},
{"Event": {"title": [{"type":"text", "text": {"content": "PRs"}}]}, "Count": {"number": 0}},
{"Event": {"title": [{"type":"text", "text": {"content": "Commits"}}]}, "Count": {"number": 0}},
{"Event": {"title": [{"type":"text", "text": {"content": "Open Issues"}}]}, "Count": {"number": 0}}
]

dashboard = GithubOverviewDashboard(NOTION_TOKEN, parent_page_id=parent_page_id)
dashboard = GithubOverviewDashboard(args.notion_token, parent_page_id=parent_page_id)
# dashboard = GithubOverviewDashboard(NOTION_TOKEN, parent_page_id=parent_page_id)
# if the dashboard already exists it will just get the database_id for it
dashboard.create_dashboard(start_records)
return dashboard
Expand All @@ -43,9 +44,9 @@ def update_overview_dashboard(repo, dashboard):
dashboard.update_dashboard(commits=n_commits, pr=open_prs, contributors=n_contributors, open_issues=open_issues)


def initialize_contributor_dashboard(parent_page_id):
def initialize_contributor_dashboard(args, parent_page_id):
start_records = []
dashboard = GithubContributorsDashboard(NOTION_TOKEN, parent_page_id, n_contributors=5)
dashboard = GithubContributorsDashboard(args.notion_token, parent_page_id, n_contributors=5)
# if the dashboard already exists it will just get the database_id for it
dashboard.create_dashboard(dashboard.parse_contributors(start_records, as_records=True))
return dashboard
Expand All @@ -60,18 +61,23 @@ def update_contributor_dashboard(repo, dashboard):
if __name__=="__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--config", type=str)
parser.add_argument("--notion-token", type=str)
parser.add_argument("--github-token", type=str)

args = parser.parse_args()
print("Got following args:")
print(args)

config = get_config(args.config)

for project_group in config:
for project in config[project_group]:
print(project)
repo = GithubHandler(GITHUB_TOKEN, project["github_org"], project["github_repo"])
overview_dashboard = initialize_overview_dashboard(project["notion_page_id"])
repo = GithubHandler(args.github_token, project["github_org"], project["github_repo"])
overview_dashboard = initialize_overview_dashboard(args, project["notion_page_id"])
update_overview_dashboard(repo, overview_dashboard)

contributor_dashboard = initialize_contributor_dashboard(project["notion_page_id"])
contributor_dashboard = initialize_contributor_dashboard(args, project["notion_page_id"])
update_contributor_dashboard(repo, contributor_dashboard)


Expand Down

0 comments on commit e080a9e

Please sign in to comment.