Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

automate skill label in skills.json #122

Merged
merged 15 commits into from
Mar 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sync_community_skills/.flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length = 79
insert_final_newline = true
15 changes: 15 additions & 0 deletions sync_community_skills/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"

[packages]
PyGithub = "*"

[dev-packages]
TimidRobot marked this conversation as resolved.
Show resolved Hide resolved
black = "==20.8b1"
flake8 = "*"
isort = "*"

[requires]
python_version = "3"
253 changes: 253 additions & 0 deletions sync_community_skills/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 83 additions & 0 deletions sync_community_skills/get_community_skills.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env python3
# vim: set fileencoding=utf-8:
"""
TimidRobot marked this conversation as resolved.
Show resolved Hide resolved
This script gets the data from the Github API to get the names and
languages of all the repositories of the 'Creative Commons' organization
and generate the required skills.json
"""

# Standard library
import json
import logging
import os
import sys
import traceback

# Third-party
from github import Github

logger = logging.getLogger("sync_community_skills")

GITHUB_ORGANIZATION = "creativecommons"
GITHUB_TOKEN = os.environ["ADMIN_GITHUB_TOKEN"]
TimidRobot marked this conversation as resolved.
Show resolved Hide resolved


class ScriptError(Exception):
def __init__(self, message, code=None):
self.code = code if code else 1
message = "({}) {}".format(self.code, message)
super(ScriptError, self).__init__(message)


def generate_databag():
"""
This method pulls the names and languages from the 'PyGithub'
and loads them into the databag after a little formatting and
then this databag will be used to generate the required skills.json
The databag schema is down below:
databag schema
{
"name": "",
"languages": []
}
"""
print("Pulling from OS@CC...")
github_client = Github(GITHUB_TOKEN)
cc = github_client.get_organization(GITHUB_ORGANIZATION)
repos = list(cc.get_repos())
if not repos:
raise ScriptError(
"Unable to setup the Github Client to get the requested"
" Github organization and the repos of that organization"
)
repos.sort(key=lambda repo: repo.name)
data = []
for repo in repos:
data.append({"name": repo.name, "languages": repo.get_languages()})
return data


def generate_skills():
"""
Writing the result array into skills.json file
"""
print(json.dumps(generate_databag(), indent=2, sort_keys=True))


if __name__ == "__main__":
try:
generate_skills()
except SystemExit as e:
sys.exit(e.code)
except KeyboardInterrupt:
logger.log(logging.INFO, "Halted via KeyboardInterrupt.")
sys.exit(130)
except ScriptError:
error_type, error_value, error_traceback = sys.exc_info()
logger.log(logging.CRITICAL, f"{error_value}")
sys.exit(error_value.code)
except Exception:
logger.log(
logging.ERROR, f"Unhandled exception: {traceback.format_exc()}"
)
sys.exit(1)
12 changes: 12 additions & 0 deletions sync_community_skills/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[tool.black]
line-length = 79

[tool.isort]
import_heading_firstparty = 'First-party/Local'
import_heading_future = 'Future'
import_heading_stdlib = 'Standard library'
import_heading_thirdparty = 'Third-party'
line_length = 79
multi_line_output = 3
no_lines_before = 'LOCALFOLDER'
profile = 'black'