Skip to content

Commit

Permalink
Merge pull request #25 from jhale1805:dev
Browse files Browse the repository at this point in the history
Add support for Discord Webhooks
  • Loading branch information
thehale authored Nov 6, 2021
2 parents fec7813 + 50c9f6f commit 3659933
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ config.json
# VS Code Project Files
.vscode

# Local temp files
tmp


############################################################################
# From https://github.com/github/gitignore/blob/master/Python.gitignore
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build: instructions

run: instructions
cd ./src/github_projects_burndown_chart \
&& PYTHONPATH=. python main.py $(type) $(name)
&& PYTHONPATH=. python main.py $(type) $(name) $(opts)

test: instructions
coverage run \
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ To see Golang's progress on their current roadmap:
make run type=organization name=golang_on_deck
```

### Discord Webhook
This project also supports posting the burndown chart to a Discord Webhook. Here's how to set that up:
1. [Create a webhook](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks#:~:text=Facebook-,making%20a%20webhook,-With%20that%20in) in your Discord server.
2. Put the webhook's URL into the `discord_webhook` setting in `secrets.json`.
3. Add the `--discord` option when running the script.

```
make run type=repository name=burndown_chart_kickoff opts="--discord"
```

## Contributing
Contributions are welcome via a [Pull Request](https://docs.github.com/en/github/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request).

Expand Down
14 changes: 11 additions & 3 deletions src/github_projects_burndown_chart/chart/burndown.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import matplotlib.pyplot as plt
from datetime import datetime
import matplotlib.pyplot as plt
import os

from config import config
from gh.project import Project
Expand All @@ -19,7 +20,7 @@ def __init__(self, project: Project):

self.project: Project = project

def render(self):
def __prepare_chart(self):
end_date = self.chart_end_date_utc if self.chart_end_date_utc else self.end_date_utc
outstanding_points_by_day = self.project.outstanding_points_by_date(
self.start_date_utc,
Expand Down Expand Up @@ -52,5 +53,12 @@ def render(self):
plt.ylabel(f"Outstanding {'Points' if points_label else 'Issues'}")
plt.xlabel("Date")

# Generate Plot
def generate_chart(self, path):
self.__prepare_chart()
if not os.path.exists(path):
os.makedirs(os.path.dirname(path))
plt.savefig(path)

def render(self):
self.__prepare_chart()
plt.show()
3 changes: 2 additions & 1 deletion src/github_projects_burndown_chart/config/secrets.json.dist
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"github_token": ""
"github_token": "",
"discord_webhook": ""
}
Empty file.
13 changes: 13 additions & 0 deletions src/github_projects_burndown_chart/discord/webhook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import requests

from config import secrets

def post_burndown_chart(chart_path):
requests.post(
secrets['discord_webhook'],
json={'content': "Today's Burndown Chart"}
)
requests.post(
secrets['discord_webhook'],
files={'file': open(chart_path, 'rb')},
)
9 changes: 8 additions & 1 deletion src/github_projects_burndown_chart/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from chart.burndown import BurndownChart
from config import config
from discord import webhook
from gh.api_wrapper import get_organization_project, get_repository_project
from gh.project import Project

Expand All @@ -13,6 +14,7 @@
choices=['repository', 'organization'],
help="The type of project to generate a burndown chart for. Can be either 'organization' or 'repository'.")
parser.add_argument("project_name", help="The name of the project as it appears in the config.json")
parser.add_argument("--discord", action='store_true', help="If present, posts the burndown chart to the configured webhook")
args = parser.parse_args()

# Point the config to the correct project
Expand All @@ -26,5 +28,10 @@

# Generate the burndown chart
burndown_chart = BurndownChart(project)
burndown_chart.render()
if args.discord:
chart_path = "./tmp/chart.png"
burndown_chart.generate_chart(chart_path)
webhook.post_burndown_chart(chart_path)
else:
burndown_chart.render()
print('Done')

0 comments on commit 3659933

Please sign in to comment.