Skip to content

Commit ac200cb

Browse files
author
neatc0der
committed
#36: Adds mastodon status post to distribution workflow
1 parent f6bfc8f commit ac200cb

File tree

4 files changed

+42
-11
lines changed

4 files changed

+42
-11
lines changed

.build/mkdocs_markmap_build/distribution.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
import os
22
import sys
33
from typing import List
4+
import requests
45

56
from twine.cli import dispatch
67

7-
from mkdocs_markmap.__meta__ import PROJECT_NAME
8-
from .common import AssetDownloader, GithubHandler
8+
from mkdocs_markmap.__meta__ import PROJECT_NAME, REPOSITORY_URL
9+
from .common import AssetDownloader
10+
11+
12+
MASTODON_URL: str = "https://fosstodon.org"
913

1014

1115
class DistributionHandler(object):
1216
def __init__(self, tag: str) -> None:
13-
self._collector = AssetDownloader(tag)
17+
self._collector: AssetDownloader = AssetDownloader(tag)
1418

1519
def distribute(self, dry_run: bool = True):
1620
assets: List[str] = self._collector.get_assets_from_release()
@@ -27,3 +31,21 @@ def distribute(self, dry_run: bool = True):
2731

2832
else:
2933
dispatch(['upload', *assets])
34+
35+
36+
class MastodonHandler(object):
37+
def __init__(self, tag: str) -> None:
38+
self.tag = tag
39+
self._url: str = f"{REPOSITORY_URL}/releases/{tag}"
40+
41+
def post(self):
42+
auth_token: str = os.environ.get('MASTODON_TOKEN')
43+
if auth_token is None:
44+
print('environment variable "MASTODON_TOKEN" is not set')
45+
sys.exit(1)
46+
47+
response: requests.Response = requests.post(f"{MASTODON_URL}/api/v1/statuses", data={
48+
"status": f"🆕 {PROJECT_NAME} {self.tag}\n{self._url}",
49+
}, headers={"Authorization": f"Bearer {auth_token}"})
50+
if not response.ok:
51+
print(f"unable to post status on mastodon: {response.text} ({response.status_code})")

mkdocs_markmap/__meta__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
PACKAGE_NAME = 'mkdocs_markmap'
2-
PROJECT_NAME = PACKAGE_NAME.replace('_', '-')
3-
PROJECT_VERSION = '2.2.0'
1+
PACKAGE_NAME: str = 'mkdocs_markmap'
2+
PROJECT_NAME: str = PACKAGE_NAME.replace('_', '-')
3+
PROJECT_VERSION: str = '2.2.0'
44

5-
OWNER = 'neatc0der'
6-
REPOSITORY_NAME = f'{OWNER}/{PROJECT_NAME}'
5+
OWNER: str = 'neatc0der'
6+
REPOSITORY_NAME: str = f'{OWNER}/{PROJECT_NAME}'
7+
REPOSITORY_URL: str = f'https://github.com/{REPOSITORY_NAME}'

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from setuptools import setup, find_packages
33
from typing import List
44

5-
from mkdocs_markmap.__meta__ import PROJECT_NAME, PROJECT_VERSION, REPOSITORY_NAME
5+
from mkdocs_markmap.__meta__ import PROJECT_NAME, PROJECT_VERSION, REPOSITORY_URL
66

77

88
def readme() -> str:
@@ -30,7 +30,7 @@ def get_requirements(filename: str, base_dir: str = 'requirements') -> List[str]
3030
long_description=readme(),
3131
long_description_content_type='text/markdown',
3232
keywords='mkdocs python markdown markmap mindmap include',
33-
url=f'https://github.com/{REPOSITORY_NAME}',
33+
url=REPOSITORY_URL,
3434
author='neatc0der',
3535
author_email='',
3636
license='MIT',

tasks.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
sys.path.insert(0, str(PROJECT_PATH / '.build'))
99

1010
from mkdocs_markmap.__meta__ import PROJECT_VERSION
11-
from mkdocs_markmap_build.distribution import DistributionHandler
11+
from mkdocs_markmap_build.distribution import DistributionHandler, MastodonHandler
1212
from mkdocs_markmap_build.info import ReleaseInfo
1313
from mkdocs_markmap_build.release import ReleaseHandler
1414

@@ -64,6 +64,14 @@ def info(c, tag=None, github=False, pypi=False):
6464

6565

6666
@task
67+
def mastodon(c, tag=TARGET_TAG):
68+
print(f'post status: {tag}')
69+
70+
handler: MastodonHandler = MastodonHandler(tag)
71+
handler.post()
72+
73+
74+
@task(post=[mastodon])
6775
def distribute(c, tag=TARGET_TAG, dry_run=True):
6876
print(f'distribute release: {tag}')
6977

0 commit comments

Comments
 (0)