Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: takos22/codingame
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.2.2
Choose a base ref
...
head repository: takos22/codingame
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Loading
Showing with 7,477 additions and 780 deletions.
  1. +12 −11 .github/ISSUE_TEMPLATE/bug_report.md
  2. +8 −0 .github/ISSUE_TEMPLATE/config.yml
  3. +7 −7 .github/ISSUE_TEMPLATE/feature_request.md
  4. +158 −24 .github/actions/changelog/main.py
  5. +3 −3 .github/actions/changelog/requirements.txt
  6. +6 −2 .github/workflows/changelog.yml
  7. +21 −6 .github/workflows/lint-test.yml
  8. +2 −2 .github/workflows/publish.yml
  9. +12 −0 .github/workflows/todo.yml
  10. +21 −0 .readthedocs.yml
  11. +141 −60 CHANGELOG.rst
  12. +1 −1 LICENSE
  13. +10 −3 README.rst
  14. +1 −1 async-requirements.txt
  15. +71 −5 codingame/__init__.py
  16. +32 −2 codingame/abc.py
  17. +42 −37 codingame/clash_of_code.py
  18. +133 −15 codingame/client/async_.py
  19. +242 −55 codingame/client/base.py
  20. +4 −0 codingame/client/client.py
  21. +129 −13 codingame/client/sync.py
  22. +173 −115 codingame/codingamer.py
  23. +2 −1 codingame/exceptions.py
  24. +11 −4 codingame/http/async_.py
  25. +76 −42 codingame/http/base.py
  26. +8 −3 codingame/http/client.py
  27. +15 −3 codingame/http/sync.py
  28. +0 −84 codingame/notification.py
  29. +75 −0 codingame/notification/__init__.py
  30. +836 −0 codingame/notification/data.py
  31. +175 −0 codingame/notification/enums.py
  32. +236 −0 codingame/notification/notification.py
  33. +4 −3 codingame/state.py
  34. +5 −21 codingame/types/__init__.py
  35. +29 −20 codingame/types/clash_of_code.py
  36. +4 −8 codingame/types/codingamer.py
  37. +467 −0 codingame/types/notification.py
  38. +29 −1 codingame/utils.py
  39. +12 −11 dev-requirements.txt
  40. +0 −23 docs/.readthedocs.yml
  41. +137 −3 docs/api.rst
  42. +82 −1 docs/changelog.rst
  43. +102 −9 docs/conf.py
  44. +146 −0 docs/extensions/og_tags.py
  45. +7 −5 docs/extensions/resourcelinks.py
  46. +12 −6 docs/index.rst
  47. +6 −2 docs/requirements.txt
  48. +0 −39 docs/user_guide/async.rst
  49. +3 −3 docs/user_guide/intro.rst
  50. +180 −34 docs/user_guide/quickstart.rst
  51. +1 −1 requirements.txt
  52. +6 −7 scripts/format.sh
  53. +6 −0 scripts/full-test.sh
  54. +5 −5 scripts/lint-code.sh
  55. +3 −2 scripts/lint-docs.sh
  56. +11 −3 scripts/test.sh
  57. +4 −2 setup.cfg
  58. +5 −8 setup.py
  59. +12 −4 tests/async/conftest.py
  60. +237 −34 tests/async/test_client.py
  61. +3 −9 tests/async/test_codingamer.py
  62. +58 −0 tests/async/test_notification.py
  63. +187 −0 tests/conftest.py
  64. +67 −0 tests/mock/responses/get_clash_of_code_from_handle.json
  65. +279 −0 tests/mock/responses/get_codingamer_from_handle.json
  66. +9 −0 tests/mock/responses/get_codingamer_from_id.json
  67. +29 −0 tests/mock/responses/get_language_ids.json
  68. +700 −0 tests/mock/responses/get_last_read_notifications.json
  69. +74 −0 tests/mock/responses/get_pending_clash_of_code.json
  70. +661 −0 tests/mock/responses/get_unread_notifications.json
  71. +622 −0 tests/mock/responses/get_unseen_notifications.json
  72. +238 −0 tests/mock/responses/login.json
  73. +51 −0 tests/mock/responses/search.json
  74. +10 −4 tests/sync/conftest.py
  75. +213 −12 tests/sync/test_client.py
  76. +1 −0 tests/sync/test_codingamer.py
  77. +54 −0 tests/sync/test_notification.py
  78. +43 −1 todo.md
23 changes: 12 additions & 11 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''
title: '[BUG] '
labels: 'bug'
assignees: 'takos22'

---

**Describe the bug**
## Describe the bug
A clear and concise description of what the bug is.

**To Reproduce**
## To Reproduce
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
## Expected behavior
A clear and concise description of what you expected to happen.

**Screenshots**
## Screenshots
If applicable, add screenshots to help explain your problem.

**Python (please complete the following information):**
- Version [e.g. 3.7]
- OS: [e.g. Windows]
## Environment information:
- OS: [e.g. Windows 10]
- Python version: [e.g. 3.7.6]
- codingame module version: [e.g. 1.0.1]

**Additional context**
## Additional context
Add any other context about the problem here.
8 changes: 8 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
blank_issues_enabled: false
contact_links:
- name: Security bug report
url: https://mailxto.com/hibec0
about: To avoid leaking the security issues, send me a mail at takos2210@gmail.com.
- name: Need help?
url: https://discord.gg/PGC3eAznJ6
about: Join the discord support server
14 changes: 7 additions & 7 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
title: '[FR] '
labels: 'enhancement'
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
## Related problem
A clear and concise description of a problem this feature request is related to. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
## Wanted solution
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
## Considered alternatives
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
## Additional context
Add any other context or screenshots about the feature request here.
182 changes: 158 additions & 24 deletions .github/actions/changelog/main.py
Original file line number Diff line number Diff line change
@@ -6,7 +6,10 @@
from pydantic import BaseSettings, SecretStr
from sphobjinv import Inventory

docs_url = "https://codingame.readthedocs.io/en/latest/"
DOCS_BASE_URL = "https://codingame.readthedocs.io/en/"
STDLIB_DOCS_BASE_URL = "https://docs.python.org/"

ref_to_doc_branch = {"dev": "latest", "master": "stable"}
roles = {
"attr": "attribute",
"meth": "method",
@@ -28,51 +31,121 @@ class Settings(BaseSettings):
input_token: SecretStr
github_repository: str
github_ref: str
github_ref_name: str


def main():
settings = Settings(_env_file=".github/actions/changelog/.env")
inventory = Inventory(url=docs_url + "objects.inv")
github = Github(settings.input_token.get_secret_value())
repo = github.get_repo(settings.github_repository)
docs_changelog = repo.get_contents(
"docs/changelog.rst", settings.github_ref.split("/")[-1]
)
log("debug", f"docs/changelog.rst at {settings.github_ref_name} downloaded")

docs_url = (
DOCS_BASE_URL
+ (
settings.github_ref_name
if settings.github_ref_name.startswith("v")
else ref_to_doc_branch.get(settings.github_ref_name, "latest")
)
+ "/"
)
log("notice", f"Using docs at {docs_url}")

inventory = Inventory(url=docs_url + "objects.inv")
log("debug", "Downloaded codingame's inventory")
stdlib_inventory = Inventory(url=STDLIB_DOCS_BASE_URL + "objects.inv")
log("debug", "Downloaded stdlib's inventory")

content = docs_changelog.decoded_content.decode()
new_content = content
directives: typing.List[re.Match] = list(
re.finditer(r":(\w+):`(.+?)`", content)
)
log("debug", f"Found {len(directives)} in docs/changelog.rst")

links: typing.List[str] = []
cache: typing.Dict[str, int] = {}
stdlib_cache: typing.Dict[str, int] = {}

log("group", "Directive search")

for directive in directives:
if directive[1] == "ref":
links.append("`{} <{}>`__".format(*refs[directive[2]]))
else:
role = roles.get(directive[1], directive[1])
try:
index = [
role, name = directive.groups()
if role == "ref":
links.append("`{} <{}>`__".format(*refs[name]))
log("debug", f"Found :ref:`{name}`")
continue

role = roles.get(role, role)

index = None
stdlib = False
cached = False

if f"{role}:{name}" in cache:
index = cache[f"{role}:{name}"]
cached = True

if f"{role}:{name}" in stdlib_cache:
index = stdlib_cache[f"{role}:{name}"]
stdlib = True
cached = True

if index is None:
indexes = [
i
for _, i in inventory.suggest(
f":py:{role}:`codingame.{name}`",
with_index=True,
thresh=90,
)
]

if not indexes:
indexes = [
i
for _, i in inventory.suggest(
f":py:{role}:`codingame.{directive[2]}`",
for _, i in stdlib_inventory.suggest(
f":py:{role}:`{name}`",
with_index=True,
thresh=90,
)
][0]
except IndexError:
print(
"::warning file=CHANGELOG.rst:: "
f":py:{role}:`codingame.{directive[2]}` not found"
]
stdlib = True

if not indexes:
links.append(f"``{name}``")
log(
"warning",
f":py:{role}:`codingame.{name}` or "
f":py:{role}:`{name}` not found",
title="Directive not found",
)
links.append(f"``{directive[2]}``")
continue

obj = inventory.objects[index]
index = indexes[0]

if stdlib:
obj = stdlib_inventory.objects[index]
links.append(
f"`{obj.dispname_expanded[len('codingame.'):]} "
f"<{docs_url + obj.uri_expanded}>`__"
f"`{obj.dispname_expanded} "
f"<{STDLIB_DOCS_BASE_URL + obj.uri_expanded}>`__"
)
log("debug", f"Found :{role}:`{name}`" + " (cached)" * cached)
stdlib_cache[f"{role}:{name}"] = index
continue

obj = inventory.objects[index]
links.append(
f"`{obj.dispname_expanded[len('codingame.'):]} "
f"<{docs_url + obj.uri_expanded}>`__"
)
log("debug", f"Found :{role}:`codingame.{name}`" + " (cached)" * cached)
cache[f"{role}:{name}"] = index

log("endgroup")

for directive, link in zip(directives[::-1], links[::-1]):
new_content = (
@@ -88,6 +161,8 @@ def main():
changelog = repo.get_contents(
"CHANGELOG.rst", settings.github_ref.split("/")[-1]
)
log("debug", f"CHANGELOG.rst at {settings.github_ref_name} downloaded")

if new_content != changelog.decoded_content.decode():
repo.update_file(
changelog.path,
@@ -96,15 +171,74 @@ def main():
changelog.sha,
branch=settings.github_ref.split("/")[-1],
)
log(
"notice",
"Changelog's content changed, updated CHANGELOG.rst",
file="CHANGELOG.rst",
)
else:
log("notice", "Changelog's content hasn't changed")


LOG_PARAMETER_NAMES = {
"end_line": "endLine",
"column": "col",
"end_column": "endColumn",
}


def log(
level: str,
message: str = "",
title: str = None,
file: str = None,
line: int = None,
end_line: int = None,
column: int = None,
end_column: int = None,
):
parameters = dict(
filter(
lambda i: i[1] is not None,
{
"title": title,
"file": file,
"line": line,
"end_line": end_line,
"column": column,
"end_column": end_column,
}.items(),
)
)

print(
"::"
+ level
+ (
(
" "
+ ",".join(
f"{LOG_PARAMETER_NAMES.get(k, k)}={v}"
for k, v in parameters.items()
)
)
if parameters
else ""
)
+ "::"
+ message,
flush=True,
)


if __name__ == "__main__":
try:
main()
except Exception as e:
print(
"::error file=.github/actions/changelog/main.py,"
f"title={e.__class__.__name__}: {str(e)}:: "
+ traceback.format_exc()
log(
"error",
traceback.format_exc(),
title=f"{e.__class__.__name__}: {str(e)}",
file=".github/actions/changelog/main.py",
)
raise e from None
raise
6 changes: 3 additions & 3 deletions .github/actions/changelog/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pygithub
pydantic
sphobjinv
pygithub~=1.55
pydantic~=1.8
sphobjinv~=2.1
8 changes: 6 additions & 2 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
name: Generate CHANGELOG.rst from docs/changelog.rst

on: [push]
on:
push:
branches:
- "*"
workflow_dispatch:

jobs:
generate-changelog:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ./.github/actions/changelog
with:
token: ${{ secrets.GITHUB_TOKEN }}
Loading