Skip to content

Commit

Permalink
Automatic formatting of Social media release announcement
Browse files Browse the repository at this point in the history
A python script that depends on packages (in requirements.txt)
* requests
* markdown

able to format a social media post announcing our releases.
The script will pick, for each operator, the latest tag name and related
URL to release note, and format a message in raw markdown and HTML.

suggested use

$ python -m venv venv
$ source venv/bin/activate
$ pip install -r requirements.txt
$ python ./product_release_post.py

Limitations
There's a (currently unhandled) rate limit to the use of APIs. It is
enough for around 10 retries. When reached the script fails with error

```
KeyError: 'tag_name'
```

Signed-off-by: Carlo Lobrano <[email protected]>
  • Loading branch information
clobrano committed Sep 27, 2024
1 parent 97bd7f2 commit 1c26dfd
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
56 changes: 56 additions & 0 deletions product_release_post.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# vi: set ft=python :
import requests
import markdown

products_map = {
"NMO": "node-maintenance-operator",
"NHC": "node-healthcheck-operator",
"SNR": "self-node-remediation",
"FAR": "fence-agents-remediation",
"MDR": "machine-deletion-remediation",
}
# print(requests.get(f'https://api.github.com/repos/medik8s/{products_map["MDR"]}/releases/latest').json())

def get_latest_version(op_shortname:str) -> dict[str,str]:
response = requests.get(f'https://api.github.com/repos/medik8s/{products_map[op_shortname]}/releases/latest')
return {"tag":response.json()["tag_name"], "link": response.json()["html_url"]}


NMO = get_latest_version("NMO")
NHC = get_latest_version("NHC")
SNR = get_latest_version("SNR")
FAR = get_latest_version("FAR")
MDR = get_latest_version("MDR")

TEMPLATE = f"""
Medik8s New Releases
The Medik8s team is thrilled to announce the new releases of ours operators
* Node Maintenance Operator (NMO) {NMO["tag"]}
* Node Healthcheck Operator (NHC) {NHC["tag"]}
* Self Node Remediation (SNR) {SNR["tag"]}
* Fence Agents Remediation (FAR) {FAR["tag"]}
* Machine Deletion Remediation (MDR) {MDR["tag"]}
see our release notes for the complete list of changes
* NHC [{NMO['tag']} release note]({NMO['link']})
* SNR [{NHC['tag']} release note]({NHC['link']})
* NMO [{SNR['tag']} release note]({SNR['link']})
* FAR [{FAR['tag']} release note]({FAR['link']})
* MDR [{MDR['tag']} release note]({MDR['link']})
Feel free to explore the new operators and contact us if you need any assistance.
Do not forget to visit https://www.medik8s.io/ for the latest information on the team's operators,
Best regards from the Medik8s team.
"""

print("Raw version:")
print(TEMPLATE)

print("\nFormatted HTML version")
print(markdown.markdown(TEMPLATE))
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
requests>=2.32
markdown>=3.7

0 comments on commit 1c26dfd

Please sign in to comment.