8000 Use GitHub Issues (#265) · python/blurb_it@d482551 · GitHub
[go: up one dir, main page]

Skip to content

Commit d482551

Browse files
authored
Use GitHub Issues (#265)
* Use GitHub Issues instead of BPO * Use GH issues instead of BPO * Customize the web app url * Fix the textbox helper text * Clarify that it's the CPython GitHub issue number. * Change the form labels to GH Issue # and GH PR # Produce filename with `gh-issue-<n>` Update tests.
1 parent 668a1e9 commit d482551

File tree

9 files changed

+88
-16
lines changed

9 files changed

+88
-16
lines changed

.coveragerc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[run]
2+
dynamic_context = test_function

blurb_it/__main__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ async def handle_get(request):
3030
request_session = await get_session(request)
3131
context = {}
3232
context["client_id"] = os.environ.get("GH_CLIENT_ID")
33+
context["app_url"] = os.environ.get("APP_URL")
3334
if request_session.get("username") and request_session.get("token"):
3435
context["username"] = request_session["username"]
3536
location = request.app.router["add_blurb"].url_for()
@@ -146,10 +147,10 @@ async def handle_add_blurb_post(request):
146147
):
147148
raise web.HTTPForbidden(reason="Invalid CSRF token. Please retry.")
148149

149-
bpo_number = data.get("bpo_number", "").strip()
150+
issue_number = data.get("issue_number", "").strip()
150151
section = data.get("section", "").strip()
151152
news_entry = data.get("news_entry", "").strip() + "\n"
152-
path = await util.get_misc_news_filename(bpo_number, section, news_entry)
153+
path = await util.get_misc_news_filename(issue_number, section, news_entry)
153154
pr_number = data.get("pr_number", "").strip()
154155

155156
context = {}

blurb_it/util.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
from blurb_it import error
99

1010

11-
async def get_misc_news_filename(bpo, section, body):
11+
async def get_misc_news_filename(issue_number, section, body):
1212
date = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())
1313
nonce = await nonceify(body)
14-
path = f"Misc/NEWS.d/next/{section}/{date}.bpo-{bpo}.{nonce}.rst"
14+
path = f"Misc/NEWS.d/next/{section}/{date}.gh-issue-{issue_number}.{nonce}.rst"
1515
return path
1616

1717

@@ -57,7 +57,7 @@ async def get_installation(gh, jwt, username):
5757
"/app/installations",
5858
jwt=jwt,
5959
accept="application/vnd.github.machine-man-preview+json",
60-
):
60+
): # pragma: no cover
6161
if installation["account"]["login"] == username:
6262
return installation
6363

dev-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ coverage==6.3.2
33
pytest==7.1.1
44
pytest-aiohttp==1.0.4
55
pytest-mock==3.7.0
6+
pytest-cov==3.0.0

runtime.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
python-3.8.7
1+
python-3.10.2

templates/add_blurb.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ <h3>📜🤖 Blurb it again?</h3>
1818
<input type="hidden" name="csrf" value="{{ csrf }}">
1919
<div class="mb-3">
2020
<div class="col form-inline">
21-
<label for="bpo_number" class="form-inline">bpo-</label><input type="text" class="form-control form-inline" placeholder="12345" id="bpo_number" name="bpo_number" required>
21+
<label for="issue_number" class="form-inline">GH Issue #</label><input type="text" class="form-control form-inline" placeholder="12345" id="issue_number" name="issue_number" required>
2222
</div>
2323
<div class="col form-inline">
24-
<small id="bpo-help" class="form-text text-muted">The bugs.python.org issue number.</small>
24+
<small id="issue_number-help" class="form-text text-muted">The CPython GitHub issue number.</small>
2525
</div>
2626
</div>
2727
<div class="mb-3">
2828
<div class="col form-inline">
29-
<label for="pr_number" class="form-inline">GH-</label><input type="text" class="form-control form-inline" placeholder="12345" id="pr_number" name="pr_number" required>
29+
<label for="pr_number" class="form-inline">GH Pull Request #</label><input type="text" class="form-control form-inline" placeholder="12345" id="pr_number" name="pr_number" required>
3030
</div>
3131
<div class="col form-inline">
3232
<small id="gh-help" class="form-text text-muted">The CPython GitHub pull request number.</small>
@@ -54,7 +54,7 @@ <h3>📜🤖 Blurb it again?</h3>
5454
<div class="mb-3">
5555
<textarea class="form-control" id="news_entry" name="news_entry" rows="10" placeholder="Write your Misc/NEWS entry below.
5656
It should be a simple ReST paragraph.
57-
Don't start with '- Issue #<n>: ' or '- bpo-<n>: ' or that sort of stuff." required></textarea>
57+
Don't start with '- Issue #<n>: ' or '- gh-issue-<n>: ' or that sort of stuff." required></textarea>
5858
</div>
5959
<button type="submit" class="btn btn-primary mb-2">📜🤖 blurb it!</button>
6060
</form>

templates/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<h5 class="my-0 mr-md-auto font-weight-normal"><a href="/">📜🤖 Blurb it!</a></h5>
2121
<h5 class="my-0 mr-md-auto font-weight-normal"><a href="/howto">How do I use Blurb It?</a></h5>
2222
{% if not username %}
23-
<a class="btn btn-outline-primary btn-social btn-github" href="https://github.com/login/oauth/authorize?client_id={{ client_id }}&scope=repo&redirect_uri=https://blurb-it.herokuapp.com/add_blurb">
23+
<a class="btn btn-outline-primary btn-social btn-github" href="https://github.com/login/oauth/authorize?client_id={{ client_id }}&scope=repo&redirect_uri=https://{{ app_url }}/add_blurb">
2424
<span class="fa fa-github"></span>
2525
Sign in with GitHub
2626
</a>

templates/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ <h1 class="display-4">📜🤖 Blurb it!</h1>
88
</div>
99

1010
<p class="lead text-center">
11-
<a class="btn btn-social btn-github" href="https://github.com/login/oauth/authorize?client_id={{ client_id }}&scope=repo&redirect_uri=https://blurb-it.herokuapp.com/add_blurb">
11+
<a class="btn btn-social btn-github" href="https://github.com/login/oauth/authorize?client_id={{ client_id }}&scope=repo&redirect_uri=https://{{ app_url}}/add_blurb">
1212
<span class="fa fa-github"></span>
1313
Sign in with GitHub
1414
</a>

tests/test_util.py

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,25 @@
22

33
import pytest
44

5-
from blurb_it import util
5+
from blurb_it import util, error
66
from aiohttp.test_utils import make_mocked_request
7-
from aiohttp_session import (Session, SESSION_KEY)
7+
from aiohttp_session import Session, SESSION_KEY
8+
9+
10+
class FakeGH:
11+
def __init__(self, *, getiter=None, getitem=None, post=None):
12+
self._getitem_return = getitem
13+
self._getiter_return = getiter
14+
self._post_return = post
15+
self.getitem_url = None
16+
self.getiter_url = None
17+
self.post_url = []
18+
self.post_data = []
19+
20+
async def getiter(self, url, jwt=None, accept=None):
21+
self.getiter_url = url
22+
for item in self._getiter_return:
23+
yield item
824

925

1026
async def test_nonceify():
@@ -25,7 +41,7 @@ async def test_nonceify():
2541

2642
async def test_get_misc_news_filename():
2743
path = await util.get_misc_news_filename(
28-
bpo=123,
44+
issue_number=123,
2945
section="Library",
3046
body="Lorem ipsum dolor amet flannel squid normcore tbh raclette enim"
3147
"pabst tumblr wolf farm-to-table bitters. Bitters keffiyeh next"
@@ -38,7 +54,7 @@ async def test_get_misc_news_filename():
3854
)
3955

4056
assert path.startswith("Misc/NEWS.d/next/Library/")
41-
assert path.endswith(".bpo-123.Ps4kgC.rst")
57+
assert path.endswith(".gh-issue-123.Ps4kgC.rst")
4258

4359

4460
async def test_has_session():
@@ -55,6 +71,13 @@ async def test_session_context():
5571
assert session_context == {"username": "blurb", "token": "124"}
5672

5773

74+
async def test_no_session_context():
75+
request = mock_request_no_session()
76+
77+
session_context = await util.get_session_context(request)
78+
assert session_context == {}
79+
80+
5881
def mock_request_session():
5982
request = make_mocked_request("GET", "/")
6083
session = Session("identity", data=None, new=False)
@@ -65,6 +88,13 @@ def mock_request_session():
6588
return request
6689

6790

91+
def mock_request_no_session():
92+
request = make_mocked_request("GET", "/")
93+
session = Session("identity", data=None, new=False)
94+
request[SESSION_KEY] = session
95+
return request
96+
97+
6898
def test_get_csrf_token__not_existing(mocker):
6999
mocker.patch("blurb_it.util.create_csrf_token", return_value="foobar")
70100

@@ -85,3 +115,41 @@ def test_create_csrf_token():
85115
@pytest.mark.parametrize("token, match", [("a", True), ("b", False)])
86116
def test_compare_csrf_tokens__match(token, match):
87117
assert util.compare_csrf_tokens("a", token) is match
118+
119+
120+
async def test_get_installation():
121+
app_installations = [
122+
{
123+
"id": 1,
124+
"account": {
125+
"login": "octocat",
126+
"id": 1,
127+
},
128+
}
129+
]
130+
gh = FakeGH(getiter=app_installations)
131+
result = await util.get_installation( B41A gh, "fake_jwt", "octocat")
132+
assert result == app_installations[0]
133+
134+
135+
async def test_get_installation_not_found():
136+
app_installations = [
137+
{
138+
"id": 1,
139+
"account": {
140+
"login": "octocat",
141+
"id": 1,
142+
},
143+
},
144+
{
145+
"id": 1,
146+
"account": {
147+
"login": "octosaurus",
148+
"id": 1,
149+
},
150+
},
151+
]
152+
gh = FakeGH(getiter=app_installations)
153+
with pytest.raises(error.InstallationNotFound) as exc:
154+
await util.get_installation(gh, "fake_jwt", "octonauts")
155+
assert exc.value.args[0] == "Can't find installation by that user: octonauts"

0 commit comments

Comments
 (0)
0