Skip to content

Commit

Permalink
trello adjustments
Browse files Browse the repository at this point in the history
rework engineer notification to add members to card
adjust list script to list ids and members of board
  • Loading branch information
bturkus committed Apr 18, 2024
1 parent 807a28e commit bb0c64c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 16 deletions.
40 changes: 33 additions & 7 deletions ami_scripts/trello_engineer_notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,34 @@ def assign_member(card_id, engineer_name):
return None


def assign_member_to_card(card_id, engineer_name):
"""Assign a member to the card."""
member_id = os.getenv(f'TRELLO_{engineer_name.upper()}_MEMBER_ID')
if not member_id:
print(f"No member ID found for {engineer_name}")
return False

api_key = os.getenv('TRELLO_API_KEY')
token = os.getenv('TRELLO_TOKEN')
url = f"https://api.trello.com/1/cards/{card_id}/idMembers"
payload = {
'key': api_key,
'token': token,
'value': member_id
}
try:
response = requests.post(url, params=payload)
response.raise_for_status()
response_data = response.json()
if response_data: # Check if the response data is not empty
return True
except requests.exceptions.RequestException as e:
print(f"Error: {e}")
return False


def main():
card_name = args.card # Assumes the argument is the card name, not the ID.
card_name = args.card
board_id = os.getenv('TRELLO_BOARD_ID')
if not board_id:
print("Board ID is not set in the environment variables.")
Expand All @@ -123,20 +148,21 @@ def main():

list_id = get_list_id(args.engineer)
if list_id and card_id:
result = move_card(card_id, list_id, 'bottom') # Move the card and position it at the bottom
result = move_card(card_id, list_id, 'bottom')
if result and 'id' in result:
print(f"Card successfully moved to {args.engineer}'s list.")
# Notify the engineer by adding a comment to the card
notification_result = assign_member(card_id, args.engineer)
if 'id' in notification_result:
print("Engineer notified successfully.")
member_assignment_result = assign_member_to_card(card_id, args.engineer)
if member_assignment_result:
print(f"Member {args.engineer} successfully assigned to card.")
else:
print("Failed to assign member to the card.")
else:
print("Failed to notify the engineer.")
else:
print("Failed to move the card: ", result)
else:
print("Operation aborted due to missing list ID or card ID.")


if __name__ == "__main__":
main()
main()
30 changes: 21 additions & 9 deletions ami_scripts/trello_list_ids.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
import requests

def fetch_trello_lists(board_id):
def fetch_trello_lists_and_members(board_id):
# Fetch API key and token from environment variables
api_key = os.getenv('TRELLO_API_KEY')
token = os.getenv('TRELLO_TOKEN')
Expand All @@ -13,25 +13,37 @@ def fetch_trello_lists(board_id):
return

# URL to fetch all lists on a board
url = f"https://api.trello.com/1/boards/{board_id}/lists"
list_url = f"https://api.trello.com/1/boards/{board_id}/lists"
member_url = f"https://api.trello.com/1/boards/{board_id}/members"

# Parameters including the API key and token
params = {
'key': api_key,
'token': token
}

# Make the HTTP request
response = requests.get(url, params=params)
if response.status_code == 200:
lists = response.json()

# Make the HTTP request for lists
list_response = requests.get(list_url, params=params)
if list_response.status_code == 200:
lists = list_response.json()
# Print each list ID and name
print("Lists on the Board:")
for list in lists:
print(f"List Name: {list['name']}, List ID: {list['id']}")
else:
print("Failed to fetch data:", response.status_code)
print("Failed to fetch lists:", list_response.status_code)

# Make the HTTP request for members
member_response = requests.get(member_url, params=params)
if member_response.status_code == 200:
members = member_response.json()
# Print each member ID and username
print("\nMembers on the Board:")
for member in members:
print(f"Member Name: {member['fullName']}, Member Username: {member['username']}, Member ID: {member['id']}")
else:
print("Failed to fetch members:", member_response.status_code)

if __name__ == "__main__":
board_id = input("Enter the Trello board ID: ")
fetch_trello_lists(board_id)
fetch_trello_lists_and_members(board_id)

0 comments on commit bb0c64c

Please sign in to comment.