Skip to content

Commit dc6e13d

Browse files
Merge branch 'BlackPythonDevs:gh-pages' into master
2 parents 337e0c1 + 98dc084 commit dc6e13d

File tree

6 files changed

+149
-142
lines changed

6 files changed

+149
-142
lines changed

.github/workflows/conference.yml

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jobs:
1919
runs-on: ubuntu-latest
2020
env:
2121
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22+
if: ${{ github.event.action == 'opened' && startsWith(github.event.issue.title, '[CONFERENCE]') && contains(github.event.issue.labels.*.name, 'conference_accepted') }}
2223
steps:
2324
- name: Checkout repository
2425
uses: actions/checkout@v4
@@ -31,7 +32,7 @@ jobs:
3132
python-version: "3.11"
3233

3334
- name: Install dependencies
34-
run: pip install PyGithub PyYAML pre-commit
35+
run: pip install -r requirements-dev.txt
3536

3637
- name: Run script
3738
env:
@@ -51,44 +52,5 @@ jobs:
5152
delete-branch: true
5253
title: "[CONFERENCE] Update Conferences"
5354
labels: |
54-
report
5555
automated pr
56-
57-
add_comment:
58-
runs-on: ubuntu-latest
59-
60-
steps:
61-
- name: Checkout repository
62-
uses: actions/checkout@v4
63-
with:
64-
token: ${{ env.GITHUB_TOKEN }}
65-
66-
- name: Setup Python environment
67-
uses: actions/setup-python@v4
68-
with:
69-
python-version: "3.12"
70-
71-
- name: Install dependencies
72-
run: pip install -r requirements-dev.txt
73-
74-
- name: Run script
75-
env:
76-
GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }}
77-
run: |
78-
python _conferences
79-
pre-commit run --all-files --show-diff-on-failure
80-
81-
- name: Add comment to the issue
82-
uses: actions/github-script@v6
83-
if: ${{ github.event.action == 'opened' && startsWith(github.event.issue.title, '[CONFERENCE]') && contains(github.event.issue.labels.*.name, 'conference') }}
84-
with:
85-
github-token: ${{ secrets.GITHUB_TOKEN }}
86-
script: |
87-
const issueNumber = context.payload.issue.number;
88-
const comment = "Automated issue, no action is required.";
89-
90-
await github.issues.createComment({
91-
...context.repo,
92-
issue_number: issueNumber,
93-
body: comment
94-
});
56+
conference
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Conference AutoResponder
2+
3+
on:
4+
issues:
5+
types: [opened]
6+
7+
permissions:
8+
issues: write
9+
10+
jobs:
11+
add_comment:
12+
runs-on: ubuntu-latest
13+
14+
env:
15+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16+
17+
steps:
18+
- name: Add initial comment to the issue
19+
uses: actions/github-script@v6
20+
if: ${{ github.event.action == 'opened' && startsWith(github.event.issue.title, '[CONFERENCE]') && contains(github.event.issue.labels.*.name, 'conference') }}
21+
with:
22+
github-token: ${{ secrets.GITHUB_TOKEN }}
23+
script: |
24+
const issueNumber = context.issue.number;
25+
const comment = "Thank you for submitting this issue. A member of the triage team will review the information and followup on this request. There is no code action to be taken.";
26+
github.rest.issues.createComment({
27+
...context.repo,
28+
issue_number: issueNumber,
29+
body: comment
30+
});
31+
32+
- name: Add approved comment
33+
uses: actions/github-script@v6
34+
if: ${{ github.event.action == 'opened' && startsWith(github.event.issue.title, '[CONFERENCE]') && contains(github.event.issue.labels.*.name, 'conference_accepted') }}
35+
with:
36+
script: |
37+
const issueNumber = context.issue.number;
38+
const comment = "Your conference submission has been accepted. You will shortly see your conference on the website."
39+
40+
github.rest.issues.createComment({
41+
...context.repo,
42+
issue_number: issueNumber,
43+
body: comment
44+
});

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ GEM
261261
rb-fsevent (0.11.2)
262262
rb-inotify (0.11.1)
263263
ffi (~> 1.0)
264-
rexml (3.3.7)
264+
rexml (3.3.8)
265265
rouge (3.30.0)
266266
rubyzip (2.3.2)
267267
safe_yaml (1.0.5)

_conferences/__main__.py

Lines changed: 100 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,100 @@
1-
import datetime
2-
import pathlib
3-
from urllib.parse import urlparse
4-
from typing import Iterator
5-
6-
import json
7-
import gh_issues
8-
9-
10-
QUERY = "repo:blackpythondevs/blackpythondevs.github.io type:issue label:conference"
11-
12-
13-
def get_conference_issues(
14-
query: str = QUERY,
15-
) -> Iterator[gh_issues.Issue]: # pragma no cover
16-
issues = gh_issues.issues_by_query(query)
17-
return issues
18-
19-
20-
def normalize_url(url_match: str | None) -> str | None:
21-
"""
22-
Parse the url and see if a scheme (`https`) is included in it.
23-
If not, then prepend `https` to the url from the issue body
24-
25-
This guards against the website thinking the passed in url is another page on https://blackpythondevs.com/
26-
"""
27-
if url_match:
28-
parsed_url = urlparse(url_match)
29-
30-
if "http" not in parsed_url.scheme.casefold():
31-
return f"https://{url_match}"
32-
else:
33-
return url_match
34-
35-
36-
def write_conferences_to_file(confs: list[dict]):
37-
# Write the conferences to the _data/conferences.yml file
38-
conferences_path.write_text(json.dumps(confs))
39-
40-
41-
def __to_conference_date(conference_date: str) -> datetime.date:
42-
return datetime.date.fromisoformat(conference_date)
43-
44-
45-
def parse_conference(issue: gh_issues.Issue) -> dict[str, str | None]:
46-
"""convert an issue to a dictionary of parsed data"""
47-
48-
KEYS = [
49-
"conference_name",
50-
"url",
51-
"conference_start_date",
52-
"conference_end_date",
53-
"conference_type",
54-
"conference_location",
55-
"summary",
56-
"speaking",
57-
]
58-
59-
_issue = {k: getattr(issue, k, None) for k in KEYS}
60-
_issue["url"] = normalize_url(_issue.get("url", None))
61-
return _issue
62-
63-
64-
def _validate_issue(issue: gh_issues.Issue, date_to_check: str) -> bool:
65-
"""Validate an issue based on its `date_to_check`"""
66-
if not (valid_date := getattr(issue, date_to_check, False)):
67-
return False
68-
else:
69-
return __to_conference_date(valid_date) >= datetime.date.today()
70-
71-
72-
def build_conferences() -> list[dict[str, str | None]]: # pragma: no cover
73-
return [
74-
parse_conference(issue)
75-
for issue in get_conference_issues()
76-
if _validate_issue(issue, "conference_end_date")
77-
]
78-
79-
80-
if __name__ == "__main__": # pragma: no cover
81-
ROOT = pathlib.Path(__file__).parent.parent
82-
conferences_path = ROOT.joinpath("_data/conferences.json")
83-
conferences = build_conferences()
84-
conferences_path.write_text(
85-
json.dumps(
86-
list(
87-
sorted(
88-
conferences,
89-
key=lambda x: __to_conference_date(x["conference_start_date"]),
90-
)
91-
),
92-
indent=2,
93-
)
94-
)
1+
import datetime
2+
import json
3+
import pathlib
4+
from typing import Iterator
5+
from urllib.parse import urlparse
6+
7+
import gh_issues
8+
9+
QUERY = "repo:blackpythondevs/blackpythondevs.github.io type:issue label:conference"
10+
11+
12+
def get_conference_issues(
13+
query: str = QUERY,
14+
) -> Iterator[gh_issues.Issue]: # pragma no cover
15+
issues = gh_issues.issues_by_query(query)
16+
return issues
17+
18+
19+
def normalize_url(url_match: str | None) -> str | None:
20+
"""
21+
Parse the url and see if a scheme (`https`) is included in it.
22+
If not, then prepend `https` to the url from the issue body
23+
24+
This guards against the website thinking the passed in url is another page on https://blackpythondevs.com/
25+
"""
26+
if url_match:
27+
parsed_url = urlparse(url_match)
28+
url_scheme = parsed_url.scheme
29+
30+
# If "https" is already the scheme, then we're good and don't need to do anything else
31+
if url_scheme == "https":
32+
return url_match
33+
34+
# If the scheme is not "https", then we need to prepend "https" to the url
35+
if url_scheme.strip() == "":
36+
return f"https://{url_match}"
37+
else:
38+
# If the scheme is a valid protocol (ftp, http, etc.),
39+
# but not "https", then we need to replace it with "https"
40+
return url_match.replace(parsed_url.scheme, "https")
41+
42+
43+
def write_conferences_to_file(confs: list[dict]):
44+
# Write the conferences to the _data/conferences.yml file
45+
conferences_path.write_text(json.dumps(confs))
46+
47+
48+
def __to_conference_date(conference_date: str) -> datetime.date:
49+
return datetime.date.fromisoformat(conference_date)
50+
51+
52+
def parse_conference(issue: gh_issues.Issue) -> dict[str, str | None]:
53+
"""convert an issue to a dictionary of parsed data"""
54+
55+
KEYS = [
56+
"conference_name",
57+
"url",
58+
"conference_start_date",
59+
"conference_end_date",
60+
"conference_type",
61+
"conference_location",
62+
"summary",
63+
"speaking",
64+
]
65+
66+
_issue = {k: getattr(issue, k, None) for k in KEYS}
67+
_issue["url"] = normalize_url(_issue.get("url", None))
68+
return _issue
69+
70+
71+
def _validate_issue(issue: gh_issues.Issue, date_to_check: str) -> bool:
72+
"""Validate an issue based on its `date_to_check`"""
73+
if not (valid_date := getattr(issue, date_to_check, False)):
74+
return False
75+
else:
76+
return __to_conference_date(valid_date) >= datetime.date.today()
77+
78+
79+
def build_conferences() -> list[dict[str, str | None]]: # pragma: no cover
80+
return [
81+
parse_conference(issue)
82+
for issue in get_conference_issues()
83+
if _validate_issue(issue, "conference_end_date")
84+
]
85+
86+
87+
if __name__ == "__main__": # pragma: no cover
88+
ROOT = pathlib.Path(__file__).parent.parent
89+
conferences_path = ROOT.joinpath("_data/conferences.json")
90+
conferences = build_conferences()
91+
j_conferences = json.dumps(
92+
list(
93+
sorted(
94+
conferences,
95+
key=lambda x: __to_conference_date(x["conference_start_date"]),
96+
)
97+
),
98+
indent=2,
99+
)
100+
conferences_path.write_text(f"{j_conferences}\n")

requirements-dev.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
black
21
ephemeral_port_reserve
32
gh-issues
43
pre-commit
5-
pytest-mock
6-
pytest-pyodide
74
pytest-playwright
85
pytest-xprocess
9-
PyGithub
10-
PyYAML

tests/tests_conferences.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
)
4646

4747

48-
@pytest.mark.parametrize("test_url", ["pycon.us", "https://pycon.us"])
48+
@pytest.mark.parametrize("test_url", ["pycon.us", "https://pycon.us", "ftp://pycon.us"])
4949
def test_normalize_url(test_url: str):
5050
"""
5151
Tests that urls are valid URLs with https:// protocols

0 commit comments

Comments
 (0)