Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENG-461 Move reviewkitteh from demos_internal #26

Merged
merged 4 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions reviewkitteh/autokitteh.yaml
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
52 changes: 52 additions & 0 deletions reviewkitteh/program.star
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))