-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve logging and code organization
- improve logging - use root logger - easier/less code - exposes debug messages of third-party libraries - add success() and change_indent() to root logger for easier invocation and fewer imports - fix indent level handling - reduce indent and use gray color to reduce distraction of non-esssential punctation - standardize "done." messags and log level - improve code organization - move asana into its own file - reduce duplication with gh_utils - remove detritus from when each script had their own environment - clean-up whitespace
- Loading branch information
1 parent
9c37348
commit e7c21b7
Showing
16 changed files
with
244 additions
and
352 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Standard library | ||
import logging | ||
import os | ||
import sys | ||
|
||
# Third-party | ||
import asana | ||
|
||
# To see workspace GID, log into Asana and then view: | ||
# https://app.asana.com/api/1.0/workspaces | ||
ASANA_WORKSPACE_GID = "133733285600979" | ||
# To see project GIDs, log into Asana and then view: | ||
# https://app.asana.com/api/1.0/projects | ||
# | ||
# To see "Community Team Tracking" project section GIDs, log into Asana and | ||
# then view: | ||
# https://app.asana.com/api/1.0/projects/1172465506923657/sections | ||
ASANA_SECTION_GID = "1172465506923661" | ||
LOG = logging.root | ||
|
||
|
||
def setup_asana_client(): | ||
LOG.info("Setting up Asana client...") | ||
try: | ||
asana_token = os.environ["ADMIN_ASANA_TOKEN"] | ||
except KeyError: | ||
LOG.critical("missin ADMIN_ASANA_TOKEN environment variable") | ||
sys.exit(1) | ||
asana_client = asana.Client.access_token(asana_token) | ||
asana_client.headers = {"asana-enable": "new_goal_memberships"} | ||
try: | ||
# Perform simple API operation to test authentication | ||
asana_client.workspaces.get_workspace(ASANA_WORKSPACE_GID) | ||
except asana.error.NoAuthorizationError as e: | ||
LOG.critical(f"{e.status} {e.message} (is ADMIN_ASANA_TOKEN valid?)") | ||
sys.exit(1) | ||
LOG.success("done.") | ||
return asana_client | ||
|
||
|
||
def get_asana_team_members(asana_client): | ||
LOG.info("Get Team Members...") | ||
team_members = asana_client.tasks.find_by_section( | ||
ASANA_SECTION_GID, opt_fields=["name", "custom_fields"] | ||
) | ||
LOG.success("done.") | ||
return team_members |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,4 @@ | ||
#!/usr/bin/env python3 | ||
# vim: set fileencoding=utf-8: | ||
|
||
# Standard library | ||
import inspect | ||
import json | ||
import logging | ||
import os | ||
|
@@ -12,33 +8,25 @@ | |
import git | ||
|
||
# First-party/Local | ||
import ccos.log | ||
from ccos.gh_utils import GITHUB_ORGANIZATION, get_credentials | ||
|
||
GIT_USER_NAME = "CC creativecommons.github.io Bot" | ||
GIT_USER_EMAIL = "[email protected]" | ||
|
||
GITHUB_USERNAME = "cc-creativecommons-github-io-bot" | ||
GITHUB_ORGANIZATION = "creativecommons" | ||
GITHUB_REPO_NAME = "creativecommons.github.io-source" | ||
|
||
GITHUB_TOKEN = os.environ["ADMIN_GITHUB_TOKEN"] | ||
GITHUB_REPO_URL_WITH_CREDENTIALS = ( | ||
f"https://{GITHUB_USERNAME}:{GITHUB_TOKEN}" | ||
f"@github.com/{GITHUB_ORGANIZATION}/{GITHUB_REPO_NAME}.git" | ||
) | ||
|
||
GIT_USER_EMAIL = "[email protected]" | ||
GIT_USER_NAME = "CC creativecommons.github.io Bot" | ||
JSON_FILE_DIR = "databags" | ||
|
||
log_name = os.path.basename(os.path.splitext(inspect.stack()[-1].filename)[0]) | ||
LOG = logging.getLogger(log_name) | ||
ccos.log.reset_handler() | ||
LOG = logging.root | ||
|
||
|
||
def set_up_repo(git_working_dir): | ||
github_username, github_token = get_credentials() | ||
github_repo_url_with_credentials = ( | ||
f"https://{github_username}:{github_token}" | ||
f"@github.com/{GITHUB_ORGANIZATION}/{GITHUB_REPO_NAME}.git" | ||
) | ||
if not os.path.isdir(git_working_dir): | ||
LOG.info("Cloning repo...") | ||
repo = git.Repo.clone_from( | ||
url=GITHUB_REPO_URL_WITH_CREDENTIALS, to_path=git_working_dir | ||
url=github_repo_url_with_credentials, to_path=git_working_dir | ||
) | ||
else: | ||
LOG.info("Setting up repo...") | ||
|
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
Oops, something went wrong.