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

[feature] Add github action to notify users about open pull-requests #5

Open
wants to merge 50 commits into
base: feature/gh-action-prs
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
0b43342
action
danimtb Oct 4, 2023
a5b0bd5
change
danimtb Oct 4, 2023
88e45bd
change 2
danimtb Oct 4, 2023
97a791f
checkout
danimtb Oct 4, 2023
1655508
Merge branch 'master' into feature/gh-action
danimtb Oct 4, 2023
908072b
fix
danimtb Oct 4, 2023
8ce98ad
Merge branch 'master' into feature/gh-action2
danimtb Oct 4, 2023
ef2c570
fix format
danimtb Oct 4, 2023
3eaf066
Merge branch 'master' into feature/gh-action2
danimtb Oct 4, 2023
de19db1
switch to python
danimtb Oct 4, 2023
023d11b
Merge branch 'master' into feature/gh-action2
danimtb Oct 4, 2023
dade39c
wip
danimtb Oct 4, 2023
f2de776
Merge branch 'master' into feature/gh-action2
danimtb Oct 4, 2023
88f73e7
wip
danimtb Oct 4, 2023
2338878
Merge branch 'master' into feature/gh-action2
danimtb Oct 4, 2023
d5d3c4c
wip
danimtb Oct 4, 2023
5118e42
Merge branch 'master' into feature/gh-action2
danimtb Oct 4, 2023
33c94b8
change
danimtb Oct 4, 2023
d25a96e
Merge branch 'master' into feature/gh-action2
danimtb Oct 4, 2023
8ec68b2
improved
danimtb Oct 4, 2023
b6089d8
Merge branch 'master' into feature/gh-action2
danimtb Oct 4, 2023
ee94671
wip
danimtb Oct 4, 2023
a10e97b
Merge branch 'master' into feature/gh-action2
danimtb Oct 4, 2023
bbed4b6
wip
danimtb Oct 4, 2023
fa0440e
Merge branch 'master' into feature/gh-action2
danimtb Oct 4, 2023
9ca18b7
fix
danimtb Oct 4, 2023
12b903c
Merge branch 'master' into feature/gh-action2
danimtb Oct 4, 2023
4bca0cd
fix
danimtb Oct 4, 2023
1c31617
Merge branch 'master' into feature/gh-action2
danimtb Oct 4, 2023
f393c73
fix
danimtb Oct 4, 2023
7cbc3a3
Merge branch 'master' into feature/gh-action2
danimtb Oct 4, 2023
b87cdb9
kk
danimtb Oct 4, 2023
c759818
Merge branch 'master' into feature/gh-action2
danimtb Oct 4, 2023
8a388ea
comment
danimtb Oct 4, 2023
afd345e
Merge branch 'master' into feature/gh-action2
danimtb Oct 4, 2023
a5a28df
fix
danimtb Oct 4, 2023
64853f6
Merge branch 'master' into feature/gh-action2
danimtb Oct 4, 2023
4348ad5
decrese limit
danimtb Oct 4, 2023
e429b2d
Merge branch 'master' into feature/gh-action2
danimtb Oct 4, 2023
5e3d8aa
format
danimtb Oct 4, 2023
264b09a
Merge branch 'master' into feature/gh-action2
danimtb Oct 4, 2023
dd4ec69
fix string
danimtb Oct 5, 2023
b85d6f8
Merge branch 'master' into feature/gh-action2
danimtb Oct 5, 2023
c07c5c7
change name
danimtb Oct 5, 2023
94930fa
Merge branch 'master' into feature/gh-action2
danimtb Oct 5, 2023
19273a9
update message
danimtb Oct 5, 2023
b9d626a
Revert "change"
danimtb Oct 5, 2023
f759cc3
Revert "change 2"
danimtb Oct 5, 2023
cf384df
Update .github/workflows/prs-user-limit.yml
danimtb Oct 5, 2023
4aa4ce3
Update .github/workflows/prs-user-limit.yml
danimtb Oct 5, 2023
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
71 changes: 71 additions & 0 deletions .github/actions/check-open-prs-per-user/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: 'Open pull-requests per user'
description: 'Check the number of pull-requests open per user, if the number is higher than the threshold, post a nice comment'
author: 'danimtb'
inputs:
threshold:
description: "Maximum number of pull-requests open per user"
required: true
default: "10"
comment:
description: "Comment to post in the pull-request when the limit of open PRs is reached"
required: true
default: "You have some pull-requests open. Please consider working on them first :smile:"
runs:
using: "composite"
steps:
- uses: actions/setup-python@v4
with:
python-version: "3.8"

- name: Install requirements
shell: bash
run: |
pip install PyGithub==2.1.1

- name: Check open PRs
id: check-prs
shell: python
env:
GITHUB_TOKEN: ${{ github.token }}
PYTHONPATH: ${{github.workspace}}
run: |
import os
from github import Github
import json

threshold = int(${{ inputs.threshold }})
comment = "${{ inputs.comment }}"
username = "${{ github.event.pull_request.user.login }}"

# Create a Github instance with your token
g = Github(os.environ["GITHUB_TOKEN"])

# Get the repository full name and pull request number from the event payload
with open(os.environ["GITHUB_EVENT_PATH"], "r") as event_file:
event_payload = json.load(event_file)
repo_full_name = event_payload["repository"]["full_name"]
pr_number = event_payload["pull_request"]["number"]

# Define the username whose PRs you want to check
username = "${{ github.event.pull_request.user.login }}"

# Get the repository and pull request objects
repo = g.get_repo(repo_full_name)
pr = repo.get_pull(pr_number)

# Get all open pull requests in the repository
open_prs = [p for p in repo.get_pulls(state="open")]

# Filter open PRs created by the specified username
user_open_prs = [p for p in open_prs if p.user.login == username]

# Sort user open PRs by their creation date in ascending order
user_open_prs = sorted(user_open_prs, key=lambda p: p.created_at)

# Check the number of open PRs and the specified threshold
if len(user_open_prs) > threshold:
# Post a comment on the current pull request if the threshold is reached
user_open_prs_str = "#" + ", #".join([str(pr.number) for pr in user_open_prs])
user_open_prs_len = len(user_open_prs)
comment_text = comment.format(username=username, user_open_prs_str=user_open_prs_str, user_open_prs_len=user_open_prs_len)
pr.create_issue_comment(comment_text)
18 changes: 18 additions & 0 deletions .github/workflows/prs-user-limit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: "[service] Check open pull-requests per user"

on:
pull_request_target:
types: [opened]

jobs:
comment:
if: github.repository == 'conan-io/conan-center-index'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: master
- uses: ./.github/actions/check-open-prs-per-user
with:
threshold: "8"
comment: "Hello @{username}, we've noticed you have [several pull-requests open](https://github.com/conan-io/conan-center-index/pulls/{username}) :open_file_folder:\\n\\nTo ensure a good experience for all, we aim to moderate the system load.\\nWe'd appreciate it if you could keep the number of open pull-requests between 5 and 10 :handshake:\\n\\nYour cooperation is valued, thank you! :smile:"