reviewer badge for notification for chaoss slack - #508
Conversation
Signed-off-by: AJ-droi <ajiriosiobe@gmail.com>
Signed-off-by: AJ-droi <ajiriosiobe@gmail.com>
|
Hi @adeyinkaoresanya, Here is my PR for issue #482. |
|
@AJ-droi Dated 05/05/26 Currently, I am working on refactoring the Thank you once again! |
|
Hello @AJ-droi As promised, I'm reaching out with an update. I have completed the refactor, and we are excited about the results. The script is now approximately 95% more efficient and significantly easier to maintain. Because of these changes, your current PR no longer aligns with the updated code structure. I really appreciate the work you have already put into it, and I would still love to see your contribution included if you are interested in updating it. If you'd like to continue, I would ask that the implementation follow the new design pattern, integrate cleanly with the refactored codebase, and run through Please let me know whether you'd like to take this on, and I'd be happy to answer any questions or provide guidance on the new structure. Thank you again for your patience and for your contribution to the project. |
Signed-off-by: AJ <ajiriosiobe@gmail.com>
Signed-off-by: AJ <ajiriosiobe@gmail.com>
|
Hi @adeyinkaoresanya, I have integrated the badge reviewer to scripts/main.py. |
Acknowledged! I will look into it soon. Thank you very much! |
Thank you, I await your review |
There was a problem hiding this comment.
@AJ-droi Thanks for the contribution. The overall implementation looks good. I reviewed it mainly for correctness and runtime safety. There are a few changes that should be addressed before merge.
Required changes
1. Validate required environment variables at start up
The module initializes Slack using environment variables without checking if they exist:
SLACK_BOT_TOKEN = os.getenv("SLACK_BOT_TOKEN")
SLACK_CHANNEL_ID = os.getenv("SLACK_CHANNEL_ID")
COMMUNITY_MANAGER_ID = os.getenv("COMMUNITY_MANAGER_ID")If any of these is missing, failures will occur later and be harder to debug.
Recommendation:
Explicitly validate them:
Example:
if not SLACK_BOT_TOKEN:
raise RuntimeError("Missing SLACK_BOT_TOKEN")2. Guard against unknown badge values in is_upgrade() for future badge changes and to prevent runtime crashes:
Current implementation:
return BADGE_ORDER.index(new) > BADGE_ORDER.index(old)This can raise a ValueError if old or new contains a badge not present in BADGE_ORDER.
Recommendation:
Validate both values before indexing:
if old not in BADGE_ORDER or new not in BADGE_ORDER:
return FalseSuggested improvements (non-blocking)
3. Consider using conversations_open() before sending DMs
Current implementation sends directly to:
channel=COMMUNITY_MANAGER_IDWhile this may work, it can fail depending on workspace configuration or if the target account becomes inactive.
A more reliable approach would be:
dm = client.conversations_open(users=[COMMUNITY_MANAGER_ID])
channel_id = dm["channel"]["id"]
client.chat_postMessage(channel=channel_id, text=message)This ensures a valid DM channel exists before sending.
4. Clarify the state source
This implementation currently derives badge state from the README. If badge_state.json is no longer part of the intended architecture, please remove it to avoid redundant state sources.
5. Improve the messages
Let's make the milestone more concrete by including the reviewer’s total completed reviews and the message to the community manager more actionable
For the public channel:
message = f"""
@{username}, congratulations on earning the {badge} badge after completing {data.total} reviews! 🎉
Thank you for your continued contributions to Event DEI Badging 👏
"""For the community manager's DM:
message = f"""
Hi <@{COMMUNITY_MANAGER_ID}> 👋
Badger @{username} has unlocked the {badge} badge with {data.total} completed reviews!🎉
This could be a great opportunity to spotlight their contributions on our socials or in the next community update.
"""6. Please resolve the outstanding conflicts, especially around README.md, before merge.
Once the required changes are addressed, this should be good to go!
Thanks again!
|
|
||
| load_dotenv() | ||
|
|
||
| SLACK_BOT_TOKEN = os.getenv("SLACK_BOT_TOKEN") |
There was a problem hiding this comment.
Validate required environment variables at start up
|
|
||
| SLACK_BOT_TOKEN = os.getenv("SLACK_BOT_TOKEN") | ||
| SLACK_CHANNEL_ID = os.getenv("SLACK_CHANNEL_ID") | ||
| COMMUNITY_MANAGER_ID = os.getenv("COMMUNITY_MANAGER_ID") |
There was a problem hiding this comment.
Validate required environment variables at start up
| load_dotenv() | ||
|
|
||
| SLACK_BOT_TOKEN = os.getenv("SLACK_BOT_TOKEN") | ||
| SLACK_CHANNEL_ID = os.getenv("SLACK_CHANNEL_ID") |
There was a problem hiding this comment.
Validate required environment variables at start up
Signed-off-by: AJ <ajiriosiobe@gmail.com>
Signed-off-by: Ajiri Osiobe <ajiriosiobe@gmail.com>
Hello @adeyinkaoresanya I have made a commit for the fix to this changes you requested for. |
|
@AJ-droi Thank you for your prompt response on this. This looks good to go. I will merge as soon as I lay hold of the necessary credentials. One more thing though, is there a reason the |
I used it for my local test, let me remove it |
Signed-off-by: AJ <ajiriosiobe@gmail.com>
I have removed the badge_state.json |
Thank you! |
Pull Request Template
Summary:
Changes:
scripts/reviewer_badge_notifier.py: verify Slackchat_postMessageresponses, update state only when both public and DM posts succeed, and fixtime.sleepimport.Testing:
python scripts/reviewer_badge_notifier.py(requires valid Slack scopes andCOMMUNITY_MANAGER_ID).Additional Notes:
chat:write(andim:write) scopes; app reinstall required after scope changes.