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

Added TrelloManager #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
54 changes: 54 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
version: 2.1

executors:
my-docker-executor:
docker:
- image: cimg/python:3.11.10

jobs:
build:
executor: my-docker-executor
steps:
- checkout

- run:
name: Get uv via curl and install it
command: |
curl -LsSf https://astral.sh/uv/install.sh | sh

- persist_to_workspace:
root: /home/circleci/
paths:
- .cargo

test:
executor: my-docker-executor
steps:
- checkout

- attach_workspace:
at: /home/circleci/

- run:
name: Set-up dependencies path
command: echo 'export PATH=$HOME/.cargo/bin:$PATH' >> $BASH_ENV

- run:
name: Set-up project dependencies
command: uv sync

- run:
name: Format python files with ruff
command: uv run ruff check . --fix

- run:
name: Run test files
command: uv run pytest

workflows:
build_and_test:
jobs:
- build
- test:
requires:
- build
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11
72 changes: 71 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,71 @@
# mAIgic-nyu
# mAIgic

This project will organize life by tracking messages and information that need follow-ups and reminding the user to take follow-ups. It will also provide a search based on individuals.

The project aims to leverage AI to track and remind for follow up messages for systems like Slack, Trello, Whatsapp, Gmail, Google Docs comments, etc.

# Technical tools

- Programming Language: Python
- Project dependency management tool: uv
- Project linter: ruff
- Project tester: pytest
- Continuous Integration (CI) tool: circleCI

# Instructions

## Setup

- Install `uv` on your system with command with `curl -LsSf https://astral.sh/uv/install.sh | sh`.
- `cd` into the cloned repository and execute `uv sync` (This will install all the dependencies).
- Activate the environment `venv` by executing `source ./.venv/bin/activate`.

## Processes

- To check the formatting standard with ruff (linter) execute either `uv run ruff check .` or `ruff check .` from the root directory of the project.
- To test the code, execute either `uv run pytest .` or `pytest .` from the root directory of the project.

Note: One can run tools like ruff and pytest independently or can run them through `uv`.

## Commit Style Guide

- Request to `strictly adhere` to the suggested commit style guide.
- The project follows Udacity's [Commit Style Guide](https://udacity.github.io/git-styleguide/).
- Reason:
- It is simple, elegant, concise and effective.
- It does not have many rules that could create confusion but yet have just enough to keep things working smoothly through clear and concise communication.

## GitHub Workflow

- Members of same team can preferably `clone` the repository.
- Make sure to push new changes to `dev` remote branch.
- Create a `Pull Request` and the changes would be reviewed and merged to the `main` remote branch. `Review` includes code, code quality, code standards, commit style guides, and Pull Request descriptions. Consistent code standards and documentation would be aided by `ruff`.
- `main` branch serves as production branch which would accumulate new changes, features and bug-fixes from `dev` branch.
- Would appreciate if you open `issues` whenever you come across any. Issues can be bugs, proposed features, performance / code improvement proposals, etc.

## Requesting access to project and CI space

- Send your`github username` to become collaborators to the project.
- Send your `email id` used to `register with circleCI` to get access to the circleCI organization to manage CI workflows and triggers. You will receive an invitation in the provided email's inbox to join the circleCI organization.
- Currently, the `magic2` CircleCI project is attached to this project.

Note: Request to keep all `communication` in the Google Chats Project Group.

## Trello Setup

- Create a Trello account.
- Go to https://trello.com/power-ups/admin to create a new Power-up.
- Check the new power-up, click `API key` on the left side panel.
- Copy the API key and visit https://trello.com/1/authorize?expiration=1day&name=yourAppName&scope=read,write&response_type=token&key=your_api_key, replace `your_api_key` with your own api key. The expiration and the name can be changed if needed.
- Create a .env file, input your API key and token:

```
TRELLO_API_KEY=your_api_key
TRELLO_OAUTH_TOKEN=your_token
```

- Run TrelloManager.py and you will see the test result.

# License

mAIgic has a MIT-style license, as found in the [LICENSE](LICENSE) file.
14 changes: 14 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[project]
name = "maigic-nyu"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.11"
dependencies = [
"numpy>=2.1.2",
"pytest>=8.3.3",
"ruff>=0.6.9",
]
[tool.ruff.lint]
select = ["ALL"]
extend-ignore = ["S101", "D211", "D213"]
98 changes: 98 additions & 0 deletions src/TrelloManager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
"""TrelloManager module interacts with the Trello API to create cards."""
import logging
import os

import requests
from dotenv import load_dotenv

load_dotenv()
# Retrieve API key and token from environment variables
api_key = os.getenv("TRELLO_API_KEY")
token = os.getenv("TRELLO_OAUTH_TOKEN")

BASE_URL = "https://api.trello.com/1"

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

HTTP_OK = 200
def get_full_board_info(short_board_id: str) -> str:
"""Get full board information from Trello.

Args:
short_board_id (str): The short ID of the Trello board.

Returns:
str: The full board ID.

"""
url = f"{BASE_URL}/boards/{short_board_id}"
query = {
"key": api_key,
"token": token,
}
response = requests.get(url, params=query, timeout=10)

if response.status_code == HTTP_OK:
board_info = response.json()
return board_info["id"]
return ""

def get_lists(board_id: str) -> list:
"""Get all lists in the specified Trello board.

Args:
board_id (str): The full ID of the Trello board.

Returns:
list: A list of list IDs.

"""
url = f"{BASE_URL}/boards/{board_id}/lists"
query = {
"key": api_key,
"token": token,
}
response = requests.get(url, params=query, timeout=10)

list_id = []
if response.status_code == HTTP_OK:
lists = response.json()
list_id = [lst["id"] for lst in lists]

return list_id

def create_card(list_id: str, name: str, desc: str) -> None:
"""Create a new card in the specified list.

Args:
list_id (str): The ID of the list where the card will be created.
name (str): The name of the card.
desc (str): The description of the card (optional).

"""
url = f"{BASE_URL}/cards"
query = {
"key": api_key,
"token": token,
"idList": list_id,
"name": name,
"desc": desc,
}
response = requests.post(url, params=query, timeout=10)

if response.status_code == HTTP_OK:
logger.info("Successfully created!")


if __name__ == "__main__":
# go to your target workspace and board, you will see a short id in your url
# example: https://trello.com/b/{short_board_id}/{board_name}
short_board_id = "your_short_board_id"
full_board_id = get_full_board_info(short_board_id)
# to simply test, I just chose the first list to add a new card
if full_board_id:
list_ids = get_lists(full_board_id)
if list_ids:
create_card(list_ids[0], "new to-do",
"This is a new task created by the bot")
16 changes: 16 additions & 0 deletions src/hello.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""Dummy file to check ruff, pytest and automatic tests with CircleCI."""

def addition(num1:int, num2:int) -> int:
"""Add 2 numebrs and return their sum."""
return num1 + num2


def main() -> int:
"""Contain the main execution logic."""
n1 = 50
n2 = 49
return addition(n1, n2)


if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Make python identify tests directory as a refernciable package."""
19 changes: 19 additions & 0 deletions tests/test_hello.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""File tests hello.py file."""

from src.hello import addition, main


def test_addition() -> None:
"""Test the addition function."""
test_7 = 7
test_0 = 0
test__2 = -2
assert addition(3, 4) == test_7
assert addition(-1, 1) == test_0
assert addition(-1, -1) == test__2


def test_main() -> None:
"""Test the main function's behavior."""
test_99 = 99
assert main() == test_99 # 50 + 49 = 99
Loading