Skip to content

Commit

Permalink
chore(release-controller): use new forum category (#833)
Browse files Browse the repository at this point in the history
Co-authored-by: CI Automation <infra@dfinity.org>
Co-authored-by: sa-github-api <138766536+sa-github-api@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 2, 2024
1 parent faf46c2 commit f708177
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 10 deletions.
14 changes: 8 additions & 6 deletions release-controller/forum.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@ def __init__(self, version_name: str, changelog: str | None, proposal: int | Non
class ReleaseCandidateForumTopic:
"""A topic in the governance category for a release candidate."""

def __init__(self, release: Release, client: DiscourseClient, governance_category):
def __init__(self, release: Release, client: DiscourseClient, nns_proposal_discussions_category):
"""Create a new topic."""
self.release = release
self.client = client
self.governance_category = governance_category
self.nns_proposal_discussions_category = nns_proposal_discussions_category
topic = next(
(t for t in client.topics_by(self.client.api_username) if self.release.rc_name in t["title"]), None
)
if topic:
self.topic_id = topic["id"]
else:
post = client.create_post(
category_id=governance_category["id"],
category_id=nns_proposal_discussions_category["id"],
content="The proposal for the next release will be announced soon.",
tags=["replica", "release"],
tags=["IC-OS-election", "release"],
title="Proposal to elect new release {}".format(self.release.rc_name),
)
if post:
Expand Down Expand Up @@ -130,14 +130,16 @@ class ReleaseCandidateForumClient:
def __init__(self, discourse_client: DiscourseClient):
"""Create a new client."""
self.discourse_client = discourse_client
self.governance_category = next(c for c in self.discourse_client.categories() if c["name"] == "Governance")
self.nns_proposal_discussions_category = next(
c for c in self.discourse_client.categories() if c["name"] == "NNS proposal discussions"
)

def get_or_create(self, release: Release) -> ReleaseCandidateForumTopic:
"""Get or create a forum topic for the given release."""
return ReleaseCandidateForumTopic(
release=release,
client=self.discourse_client,
governance_category=self.governance_category,
nns_proposal_discussions_category=self.nns_proposal_discussions_category,
)


Expand Down
6 changes: 5 additions & 1 deletion release-controller/mock_discourse.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ def categories(self):
{
"id": 5,
"name": "Governance",
}
},
{
"id": 6,
"name": "NNS proposal discussions",
},
]
)
]
Expand Down
125 changes: 122 additions & 3 deletions release-controller/test_forum.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
def test_create_release_notes_on_new_release():
"""Release notes are created when a new release is added to the index."""
discourse_client = DiscourseClientMock()
get_url = discourse_client.host + "posts/1.json"
httpretty.register_uri(
httpretty.GET,
get_url,
discourse_client.host + "posts/1.json",
body='{"raw": "bogus text", "can_edit": true}',
content_type="application/json; charset=utf-8",
)
Expand Down Expand Up @@ -68,10 +67,130 @@ def proposal(v: str):
}
assert discourse_client.created_posts == [expected_post_1, expected_post_2]

assert discourse_client.created_topics == [
{
"category_id": 6,
"tags": ["IC-OS-election", "release"],
"title": "Proposal to elect new release rc--2024-02-21_23-06",
}
]


@httpretty.activate(verbose=True, allow_net_connect=False)
def test_create_post_in_new_category():
"""Release notes are created when a new release is added to the index."""
discourse_client = DiscourseClientMock()
get_url = discourse_client.host + "posts/1.json"
httpretty.register_uri(
httpretty.GET,
get_url,
body='{"raw": "bogus text", "can_edit": true}',
content_type="application/json; charset=utf-8",
)
httpretty.register_uri(
httpretty.GET,
discourse_client.host + "posts/2.json",
body='{"raw": "bogus text", "can_edit": true}',
content_type="application/json; charset=utf-8",
)
httpretty.register_uri(
httpretty.GET,
discourse_client.host + "posts/3.json",
body='{"raw": "bogus text", "can_edit": true}',
content_type="application/json; charset=utf-8",
)
existing_post_1 = {
"raw": """\
Hello there!
We are happy to announce that voting is now open for [a new IC release](https://github.com/dfinity/ic/tree/release-2024-02-21_23-06-default).
The NNS proposal is here: [IC NNS Proposal 1](https://dashboard.internetcomputer.org/proposal/1).
Here is a summary of the changes since the last release:
release notes for version test1...
""",
"yours": True,
"topic_id": 1,
"can_edit": True,
}
existing_post_2 = {
"raw": """\
Hello there!
We are happy to announce that voting is now open for [a new IC release](https://github.com/dfinity/ic/tree/release-2024-02-21_23-06-feat).
The NNS proposal is here: [IC NNS Proposal 2](https://dashboard.internetcomputer.org/proposal/2).
Here is a summary of the changes since the last release:
release notes for version test2...
""",
"yours": True,
"topic_id": 1,
"can_edit": True,
}
discourse_client.created_posts = [existing_post_1, existing_post_2]
existing_topic = {
"category_id": 5,
"tags": ["replica", "release"],
"title": "Proposal to elect new release rc--2024-02-21_23-06",
}
discourse_client.created_topics = [existing_topic]
forum_client = ReleaseCandidateForumClient(discourse_client=discourse_client)
post = forum_client.get_or_create(
Release(
rc_name="rc--2024-02-21_23-06",
versions=[
Version(name="default", version="test1"),
Version(name="feat", version="test2"),
],
)
)

def changelog(v: str):
return f"release notes for version {v}..."

def proposal(v: str):
return int(v.removeprefix("test"))

post.update(changelog=changelog, proposal=proposal)

post = forum_client.get_or_create(
Release(
rc_name="rc--2024-02-28_23-06",
versions=[
Version(name="default", version="test3"),
],
)
)
post.update(changelog=changelog, proposal=proposal)
new_post = {
"raw": """\
Hello there!
We are happy to announce that voting is now open for [a new IC release](https://github.com/dfinity/ic/tree/release-2024-02-28_23-06-default).
The NNS proposal is here: [IC NNS Proposal 3](https://dashboard.internetcomputer.org/proposal/3).
Here is a summary of the changes since the last release:
release notes for version test3...
""",
"yours": True,
"topic_id": 2,
"can_edit": True,
}

assert discourse_client.created_posts == [existing_post_1, existing_post_2, new_post]

assert discourse_client.created_topics == [
{
"category_id": 5,
"tags": ["replica", "release"],
"title": "Proposal to elect new release rc--2024-02-21_23-06",
}
},
{
"category_id": 6,
"tags": ["IC-OS-election", "release"],
"title": "Proposal to elect new release rc--2024-02-28_23-06",
},
]

0 comments on commit f708177

Please sign in to comment.