Skip to content

Commit

Permalink
Fix truncation of good first issues when posting to Zulip
Browse files Browse the repository at this point in the history
The Zulip API has a max message size and our "good first issues"
posting hits it resulting in message truncation and a loss of
content.

This commit adds a Python script to batch up "good first issues"
content into 1 or more messages so that it doesn't get truncated.

Also includes new image to run in as we need additional dependencies
that the "post sync" image doesn't need.

And this adds a PR check to link the python script and make sure it
is all kosher.

Fixes #18
  • Loading branch information
SeanTAllen committed Dec 9, 2023
1 parent e7dd8f2 commit 8ccab72
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 12 deletions.
12 changes: 12 additions & 0 deletions .ci-dockerfiles/good-first-issues/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ARG FROM_TAG=release
FROM ghcr.io/ponylang/shared-docker-ci-x86-64-unknown-linux-builder-with-libressl-3.7.3:${FROM_TAG}

RUN apk add --update --no-cache \
pcre2-dev \
python3 \
python3-dev \
py3-pip \

RUN pip3 install --upgrade pip \
pylint \
zulip
28 changes: 28 additions & 0 deletions .ci-dockerfiles/good-first-issues/build-and-push.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

set -o errexit
set -o nounset

#
# *** You should already be logged in to GitHub Container Registrṡ when you run
# this ***
#

DOCKERFILE_DIR="$(dirname "$0")"
NAME="ghcr.io/ponylang/pony-sync-helper-ci-good-first-issues"

# built from x86-64-unknown-linux-builder release tag
FROM_TAG=release
TAG_AS=release
docker build --pull --build-arg FROM_TAG="${FROM_TAG}" \
-t "${NAME}:${TAG_AS}" \
"${DOCKERFILE_DIR}"
docker push "${NAME}:${TAG_AS}"

# built from x86-64-unknown-linux-builder latest tag
FROM_TAG=latest
TAG_AS=latest
docker build --pull --build-arg FROM_TAG="${FROM_TAG}" \
-t "${NAME}:${TAG_AS}" \
"${DOCKERFILE_DIR}"
docker push "${NAME}:${TAG_AS}"
36 changes: 35 additions & 1 deletion .github/workflows/breakage-against-linux-pony-latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,32 @@ jobs:
topic: ${{ github.repository }} scheduled job failure
content: ${{ github.server_url}}/${{ github.repository }}/actions/runs/${{ github.run_id }} failed.

rebuild-good-first-issues:
name: Update builder
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Login to GitHub Container Registry
# v2.2.0
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
run: bash .ci-dockerfiles/good-first-issues/build-and-push.bash
- name: Send alert on failure
if: ${{ failure() }}
uses: zulip/github-actions-zulip/send-message@b62d5a0e48a4d984ea4fce5dd65ba691963d4db4
with:
api-key: ${{ secrets.ZULIP_SCHEDULED_JOB_FAILURE_API_KEY }}
email: ${{ secrets.ZULIP_SCHEDULED_JOB_FAILURE_EMAIL }}
organization-url: 'https://ponylang.zulipchat.com/'
to: notifications
type: stream
topic: ${{ github.repository }} scheduled job failure
content: ${{ github.server_url}}/${{ github.repository }}/actions/runs/${{ github.run_id }} failed.

vs-ponyc-main-linux:
name: Verify main against ponyc main on Linux
needs:
Expand Down Expand Up @@ -62,12 +88,20 @@ jobs:

name: Prune untagged images
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
image:
- pony-sync-helper-ci-builder
- pony-sync-helper-ci-good-first-issues

steps:
- name: Prune
# v4.1.1
uses: actions/delete-package-versions@0d39a63126868f5eefaa47169615edd3c0f61e20
with:
package-name: 'pony-sync-helper-ci-builder'
package-name: ${{ matrix.image }}
package-type: 'container'
min-versions-to-keep: 1
delete-only-untagged-versions: 'true'
Expand Down
18 changes: 7 additions & 11 deletions .github/workflows/post-good-first-issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
name: Post good first issues to Zulip
runs-on: ubuntu-latest
container:
image: ghcr.io/ponylang/pony-sync-helper-ci-builder:release
image: ghcr.io/ponylang/pony-sync-helper-ci-good-first-issues:release
steps:
- uses: actions/checkout@v3
- name: Today's date
Expand All @@ -28,13 +28,9 @@ jobs:
} >> "$GITHUB_ENV"
env:
PONY_SYNC_HELPER_GITHUB_TOKEN: ${{ secrets.PONYLANG_MAIN_API_TOKEN }}
- name: Post Issues
uses: zulip/github-actions-zulip/send-message@b62d5a0e48a4d984ea4fce5dd65ba691963d4db4
with:
api-key: ${{ secrets.ZULIP_SYNC_EVENT_API_KEY }}
email: ${{ secrets.ZULIP_SYNC_EVENT_EMAIL }}
organization-url: 'https://ponylang.zulipchat.com/'
to: contribute to Pony
type: stream
topic: Good first issues as of ${{env.DATE}}
content: ${{ env.ISSUES }}
- name: Post to Zulip
run: /post-good-first-issues.py
env:
ZULIP_API_KEY: ${{ secrets.ZULIP_SYNC_EVENT_API_KEY }}
ZULIP_EMAIL: ${{ secrets.ZULIP_SYNC_EVENT_EMAIL }}
ZULIP_SITE: 'https://ponylang.zulipchat.com/'
10 changes: 10 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,13 @@ jobs:
run: |
corral fetch
corral run -- ponyc -Dopenssl_0.9.0
lint-post-good-first-issues:
name: Verify that post-good-first-issues.py passes linting checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build docker image
run: docker build --build-arg FROM_TAG="alpine" -t "ghcr.io/ponylang/pony-sync-helper-ci-good-first-issues:latest" .ci-dockerfiles/good-first-issues
- name: Lint post-good-first-issues.py
run: docker run --entrypoint pylint --rm "ghcr.io/ponylang/pony-sync-helper-ci-good-first-issues:latest" /post-good-first-issues.py
31 changes: 31 additions & 0 deletions post-good-first-issues.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/python3

from datetime import datetime
import os
import zulip

issues_str = os.environ['ISSUES']
issues_lines = issues_str.splitlines()

messages = []
current_message = ""
for line in issues_lines:
if len(current_message) + len(line) <= 8092
current_message += line + "\n"
else:
messages.append(current_message)
current_message = line + "\n"

# set up topic with today's date
msg_date = datetime.today().strftime('%Y-%m-%d')
msg_topic = "Good first issues as of " + msg_date

zulip_client = zulip.Client()
for message in messages:
request = {
"type": "stream",
"to": "contribute to Pony",
"topic": msg_topic,
"content": message
}
result = zulip_client.send_message(request)

0 comments on commit 8ccab72

Please sign in to comment.