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 7 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
14 changes: 14 additions & 0 deletions sync_community_skills/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"

[packages]
requests = "*"
TimidRobot marked this conversation as resolved.
Show resolved Hide resolved

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

[requires]
python_version = "3"
218 changes: 218 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.

61 changes: 61 additions & 0 deletions sync_community_skills/get_community_skills.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""
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 Lib
import json
import os


# Third Part
import requests

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 = "ccos-scripts"

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"
)
TimidRobot marked this conversation as resolved.
Show resolved Hide resolved


def generate_databag():
"""
This method pulls the names and languages from the 'Github Api'
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 the Github API")
result = []
api_request = requests.get(
"https://api.github.com/orgs/creativecommons/repos?per_page=100"
)
data = api_request.json()
for x in data:
databag = {"name": "", "languages": []}
databag["name"] = x["name"]
result.append(databag)
languages_dat_from_api = requests.get(x["languages_url"])
databag["languages"].append(languages_dat_from_api.json())
return result


"""
Writing the result array into skills.json file
"""

with open("skills.json", "w") as outfile:
json.dump(generate_databag(), outfile)
2 changes: 2 additions & 0 deletions sync_community_skills/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tool.black]
line-length = 79
Loading