-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Mostly formatting changes to match the format of the current demos. The yaml file changed the most because it did not work in its previous state.
- Loading branch information
1 parent
2f787b8
commit bda87a3
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# This YAML file is a declarative manifest that describes the setup | ||
# of the AutoKitteh project ReviewKitteh. | ||
# ReviewKitteh integrates GitHub, Google Sheets and Slack. | ||
# | ||
# Before applying this file: | ||
# - Modify the values in the project's "vars" section | ||
# | ||
# After applying this file, initialize this AutoKitteh project's | ||
# GitHub, Google Sheets and Slack connections. | ||
|
||
version: v1 | ||
|
||
project: | ||
name: reviewkitteh | ||
vars: | ||
- name: CHANNEL | ||
value: <Channel Name or ID> | ||
- name: SHEET_ID | ||
value: <Google Sheets ID> | ||
connections: | ||
- name: my_slack | ||
integration: slack | ||
- name: my_github | ||
integration: github | ||
- name: my_googlesheets | ||
integration: googlesheets | ||
triggers: | ||
- name: github_pull_request | ||
connection: my_github | ||
event_type: pull_request | ||
call: program.star:on_github_pull_request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
"""A program that listens for GitHub pull requests and meows at random people. | ||
This program listens for GitHub pull request events and posts a message to a | ||
Slack channel when a pull request is opened or reopened. It then polls the | ||
pull request until it is closed or merged, updating the message with the | ||
current state of the pull request. Every 15 seconds, it also reads a random | ||
name from a Google Sheet and pages that person in the Slack channel. | ||
""" | ||
|
||
load("@slack", "my_slack") | ||
load("@github", "my_github") | ||
load("@googlesheets", "my_googlesheets") | ||
load("env", "CHANNEL", "SHEET_ID") | ||
|
||
|
||
def on_github_pull_request(data): | ||
"""Workflow's entry-point.""" | ||
if data.action not in ["opened", "reopened"]: | ||
return | ||
|
||
pr = data.pull_request | ||
message = "%s [%s]" % (pr.links.html.h_ref, pr.state) | ||
ts = my_slack.chat_post_message(CHANNEL, message).ts | ||
|
||
i = 0 | ||
|
||
while pr.state not in ["closed", "merged"]: | ||
log("polling #%d" % i) | ||
sleep(5) | ||
|
||
pr = my_github.get_pull_request( | ||
data.repo.owner.login, data.repo.name, pr.number | ||
) | ||
message = "%s meow [%s]" % (pr.links.html.h_ref, pr.state) | ||
my_slack.chat_update(CHANNEL, ts, message) | ||
|
||
i += 1 | ||
|
||
if i % 3 == 0: | ||
# Spreadsheet contains a list of usernames | ||
rows = my_googlesheets.read_range(SHEET_ID, "A1:A5") | ||
the_chosen_one = rows[rand.intn(len(rows))][0] | ||
log("meowing at %s" % the_chosen_one) | ||
user_email = "%[email protected]" % the_chosen_one | ||
user = my_slack.users_lookup_by_email(user_email).user | ||
my_slack.chat_post_message(CHANNEL, "paging <@%s>" % user.id, thread_ts=ts) | ||
|
||
log("pr is %s" % pr.state) | ||
|
||
|
||
def log(msg): | ||
print("[%s] %s" % (time.now(), msg)) |