You've already forked wakapi-readme-stats
making commit using bot test
This commit is contained in:
18
.github/workflows/review_pr.yml
vendored
18
.github/workflows/review_pr.yml
vendored
@@ -29,10 +29,16 @@ jobs:
|
|||||||
- name: Install Dependencies 📥
|
- name: Install Dependencies 📥
|
||||||
run: pip install -r requirements.txt
|
run: pip install -r requirements.txt
|
||||||
|
|
||||||
- name: Create assets folder 📥
|
- name: Create Assets Folder 📥
|
||||||
run: mkdir assets
|
run: mkdir assets
|
||||||
|
|
||||||
|
- name: Create Previous Comments 🫣
|
||||||
|
uses: int128/hide-comment-action@v1
|
||||||
|
with:
|
||||||
|
starts-with: "README stats current output:"
|
||||||
|
|
||||||
- name: Run Action Preview on Current Code 🧪
|
- name: Run Action Preview on Current Code 🧪
|
||||||
|
id: make-stats
|
||||||
env:
|
env:
|
||||||
INPUT_GH_TOKEN: ${{ secrets.INPUT_GITHUB_TOKEN }}
|
INPUT_GH_TOKEN: ${{ secrets.INPUT_GITHUB_TOKEN }}
|
||||||
INPUT_WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
|
INPUT_WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
|
||||||
@@ -54,6 +60,12 @@ jobs:
|
|||||||
INPUT_COMMIT_BY_ME: True
|
INPUT_COMMIT_BY_ME: True
|
||||||
INPUT_DEBUG_LOGGING: True # This is for testing purpose only not for production
|
INPUT_DEBUG_LOGGING: True # This is for testing purpose only not for production
|
||||||
DEBUG_RUN: True # This is for testing purpose only not for production
|
DEBUG_RUN: True # This is for testing purpose only not for production
|
||||||
PR_NUMBER: ${{ github.event.number }} # This is for testing purpose only not for production
|
|
||||||
CURRENT_GITHUB_ACTION_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This is for testing purpose only not for production
|
|
||||||
run: python3 sources/main.py
|
run: python3 sources/main.py
|
||||||
|
|
||||||
|
- name: Create Comment
|
||||||
|
uses: jungwinter/comment@v1
|
||||||
|
with:
|
||||||
|
type: create
|
||||||
|
body: ${{ steps.run_tests.outputs.README_CONTENT }}
|
||||||
|
issue_number: ${{ github.event.number }}
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|||||||
@@ -227,7 +227,7 @@ class DownloadManager:
|
|||||||
return await DownloadManager._get_remote_resource(resource, safe_load)
|
return await DownloadManager._get_remote_resource(resource, safe_load)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def _fetch_graphql_query(query: str, use_github_action: bool = False, **kwargs) -> Dict:
|
async def _fetch_graphql_query(query: str, **kwargs) -> Dict:
|
||||||
"""
|
"""
|
||||||
Execute GitHub GraphQL API simple query.
|
Execute GitHub GraphQL API simple query.
|
||||||
:param query: Dynamic query identifier.
|
:param query: Dynamic query identifier.
|
||||||
@@ -235,7 +235,7 @@ class DownloadManager:
|
|||||||
:param kwargs: Parameters for substitution of variables in dynamic query.
|
:param kwargs: Parameters for substitution of variables in dynamic query.
|
||||||
:return: Response JSON dictionary.
|
:return: Response JSON dictionary.
|
||||||
"""
|
"""
|
||||||
headers = {"Authorization": f"Bearer {EM.GH_TOKEN if not use_github_action else EM.CURRENT_GITHUB_ACTION_TOKEN}"}
|
headers = {"Authorization": f"Bearer {EM.GH_TOKEN}"}
|
||||||
res = await DownloadManager._client.post(
|
res = await DownloadManager._client.post(
|
||||||
"https://api.github.com/graphql", json={"query": Template(GITHUB_API_QUERIES[query]).substitute(kwargs)}, headers=headers
|
"https://api.github.com/graphql", json={"query": Template(GITHUB_API_QUERIES[query]).substitute(kwargs)}, headers=headers
|
||||||
)
|
)
|
||||||
@@ -268,7 +268,7 @@ class DownloadManager:
|
|||||||
return list(), dict(hasNextPage=False)
|
return list(), dict(hasNextPage=False)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def _fetch_graphql_paginated(query: str, use_github_action: bool = False, **kwargs) -> Dict:
|
async def _fetch_graphql_paginated(query: str, **kwargs) -> Dict:
|
||||||
"""
|
"""
|
||||||
Execute GitHub GraphQL API paginated query.
|
Execute GitHub GraphQL API paginated query.
|
||||||
Queries 100 new results each time until no more results are left.
|
Queries 100 new results each time until no more results are left.
|
||||||
@@ -278,11 +278,11 @@ class DownloadManager:
|
|||||||
:param kwargs: Parameters for substitution of variables in dynamic query.
|
:param kwargs: Parameters for substitution of variables in dynamic query.
|
||||||
:return: Response JSON dictionary.
|
:return: Response JSON dictionary.
|
||||||
"""
|
"""
|
||||||
initial_query_response = await DownloadManager._fetch_graphql_query(query, use_github_action, **kwargs, pagination="first: 100")
|
initial_query_response = await DownloadManager._fetch_graphql_query(query, **kwargs, pagination="first: 100")
|
||||||
page_list, page_info = DownloadManager._find_pagination_and_data_list(initial_query_response)
|
page_list, page_info = DownloadManager._find_pagination_and_data_list(initial_query_response)
|
||||||
while page_info["hasNextPage"]:
|
while page_info["hasNextPage"]:
|
||||||
pagination = f'first: 100, after: "{page_info["endCursor"]}"'
|
pagination = f'first: 100, after: "{page_info["endCursor"]}"'
|
||||||
query_response = await DownloadManager._fetch_graphql_query(query, use_github_action, **kwargs, pagination=pagination)
|
query_response = await DownloadManager._fetch_graphql_query(query, **kwargs, pagination=pagination)
|
||||||
new_page_list, page_info = DownloadManager._find_pagination_and_data_list(query_response)
|
new_page_list, page_info = DownloadManager._find_pagination_and_data_list(query_response)
|
||||||
page_list += new_page_list
|
page_list += new_page_list
|
||||||
_, page_info = DownloadManager._find_pagination_and_data_list(initial_query_response)
|
_, page_info = DownloadManager._find_pagination_and_data_list(initial_query_response)
|
||||||
@@ -290,7 +290,7 @@ class DownloadManager:
|
|||||||
return initial_query_response
|
return initial_query_response
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def get_remote_graphql(query: str, use_github_action: bool = False, **kwargs) -> Dict:
|
async def get_remote_graphql(query: str, **kwargs) -> Dict:
|
||||||
"""
|
"""
|
||||||
Execute GitHub GraphQL API query.
|
Execute GitHub GraphQL API query.
|
||||||
The queries are defined in `GITHUB_API_QUERIES`, all parameters should be passed as kwargs.
|
The queries are defined in `GITHUB_API_QUERIES`, all parameters should be passed as kwargs.
|
||||||
@@ -298,16 +298,15 @@ class DownloadManager:
|
|||||||
Merges paginated sub-queries if pagination is required for the query.
|
Merges paginated sub-queries if pagination is required for the query.
|
||||||
Parse and return response as JSON.
|
Parse and return response as JSON.
|
||||||
:param query: Dynamic query identifier.
|
:param query: Dynamic query identifier.
|
||||||
:param use_github_action: Use GitHub actions bot auth token instead of current user.
|
|
||||||
:param kwargs: Parameters for substitution of variables in dynamic query.
|
:param kwargs: Parameters for substitution of variables in dynamic query.
|
||||||
:return: Response JSON dictionary.
|
:return: Response JSON dictionary.
|
||||||
"""
|
"""
|
||||||
key = f"{query}_{md5(dumps(kwargs, sort_keys=True).encode('utf-8')).digest()}"
|
key = f"{query}_{md5(dumps(kwargs, sort_keys=True).encode('utf-8')).digest()}"
|
||||||
if key not in DownloadManager._REMOTE_RESOURCES_CACHE:
|
if key not in DownloadManager._REMOTE_RESOURCES_CACHE:
|
||||||
if "$pagination" in GITHUB_API_QUERIES[query]:
|
if "$pagination" in GITHUB_API_QUERIES[query]:
|
||||||
res = await DownloadManager._fetch_graphql_paginated(query, use_github_action, **kwargs)
|
res = await DownloadManager._fetch_graphql_paginated(query, **kwargs)
|
||||||
else:
|
else:
|
||||||
res = await DownloadManager._fetch_graphql_query(query, use_github_action, **kwargs)
|
res = await DownloadManager._fetch_graphql_query(query, **kwargs)
|
||||||
DownloadManager._REMOTE_RESOURCES_CACHE[key] = res
|
DownloadManager._REMOTE_RESOURCES_CACHE[key] = res
|
||||||
else:
|
else:
|
||||||
res = DownloadManager._REMOTE_RESOURCES_CACHE[key]
|
res = DownloadManager._REMOTE_RESOURCES_CACHE[key]
|
||||||
|
|||||||
@@ -47,5 +47,6 @@ class EnvironmentManager:
|
|||||||
DEBUG_LOGGING = getenv("INPUT_DEBUG_LOGGING", "0").lower() in _TRUTHY
|
DEBUG_LOGGING = getenv("INPUT_DEBUG_LOGGING", "0").lower() in _TRUTHY
|
||||||
DEBUG_RUN = getenv("DEBUG_RUN", "False").lower() in _TRUTHY
|
DEBUG_RUN = getenv("DEBUG_RUN", "False").lower() in _TRUTHY
|
||||||
|
|
||||||
PR_NUMBER = int(getenv("PR_NUMBER", "0"))
|
@staticmethod
|
||||||
CURRENT_GITHUB_ACTION_TOKEN = getenv("CURRENT_GITHUB_ACTION_TOKEN", "")
|
def set_variable(name: str, content: str):
|
||||||
|
environ[name] = content
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ from re import sub
|
|||||||
from github import Github, AuthenticatedUser, Repository, ContentFile, InputGitAuthor, UnknownObjectException
|
from github import Github, AuthenticatedUser, Repository, ContentFile, InputGitAuthor, UnknownObjectException
|
||||||
|
|
||||||
from manager_environment import EnvironmentManager as EM
|
from manager_environment import EnvironmentManager as EM
|
||||||
from manager_download import DownloadManager as DM
|
|
||||||
from manager_debug import DebugManager as DBM
|
from manager_debug import DebugManager as DBM
|
||||||
|
|
||||||
|
|
||||||
@@ -111,13 +110,7 @@ class GitHubManager:
|
|||||||
"""
|
"""
|
||||||
prefix = "README stats current output:"
|
prefix = "README stats current output:"
|
||||||
DBM.i("Commenting PR...")
|
DBM.i("Commenting PR...")
|
||||||
|
EM.set_variable("GITHUB_OUTPUT", f"README_CONTENT={prefix}\n\n{stats}")
|
||||||
github = Github(EM.CURRENT_GITHUB_ACTION_TOKEN)
|
|
||||||
pull_request = github.get_repo("anmol098/waka-readme-stats").get_pull(EM.PR_NUMBER)
|
|
||||||
for comment in [ic for ic in pull_request.get_issue_comments() if ic.body.startswith(prefix)]:
|
|
||||||
await DM.get_remote_graphql("hide_outdated_comment", use_github_action=True, id=comment.id)
|
|
||||||
|
|
||||||
pull_request.create_issue_comment(f"{prefix}\n\n{stats}")
|
|
||||||
DBM.g("PR commented!")
|
DBM.g("PR commented!")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
Reference in New Issue
Block a user