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/duplicate board query #61

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
e9c2d80
Added "create board by workspace id"
albcl Jun 18, 2022
748f418
Update readme
albcl Jun 18, 2022
5480228
Added "duplicate board" query and type hint
albcl Jun 20, 2022
5dc386d
Readme updated
albcl Jun 20, 2022
ed8e29d
Merge pull request #1 from albcl/feature/create_board_by_workspace_id
albcl Jun 29, 2022
873dda3
Added extra parameters for the query
albcl Jun 29, 2022
f9e3a6e
Merge branch 'master' into feature/duplicate_board_query
albcl Jun 29, 2022
d707140
Query and tests updated
albcl Oct 18, 2022
12b6834
Readme update
albcl Oct 18, 2022
f196586
Restructured Readme
albcl Oct 18, 2022
89a5b8c
Added move_item_to_group and archive_item_by_id (#73)
tonymorello Sep 2, 2022
cdeaa30
Add id to payload of get_item_by_id_query (#74)
wbazant Oct 29, 2022
050c32d
Feature/create board by workspace (#60)
albcl Oct 29, 2022
02820ea
bump version
rhymiz Oct 29, 2022
0d41eb5
Create CODE_OF_CONDUCT.md (#78)
rhymiz Dec 1, 2022
0a9b87d
Update README.md
rhymiz Dec 1, 2022
1a30751
docs: add rhymiz as a contributor for code (#79)
allcontributors[bot] Dec 1, 2022
4340a28
docs: add tonymorello as a contributor for code (#80)
allcontributors[bot] Dec 1, 2022
cd885f8
docs: add chdastolfo as a contributor for code (#81)
allcontributors[bot] Dec 1, 2022
1837e1d
docs: add lucioseki as a contributor for code (#84)
allcontributors[bot] Dec 1, 2022
ba4e159
docs: add yogeshnile as a contributor for code (#86)
allcontributors[bot] Dec 1, 2022
af5fa68
docs: add spencersamuel7 as a contributor for code (#88)
allcontributors[bot] Dec 1, 2022
bd9358d
Update .all-contributorsrc
rhymiz Dec 1, 2022
ee25c90
Update README.md
rhymiz Dec 1, 2022
6d5b19b
Update README.md
rhymiz Dec 1, 2022
53faa21
docs: add rhymiz as a contributor for code, bug, and maintenance (#90)
allcontributors[bot] Dec 1, 2022
2153140
docs: add chdastolfo as a contributor for code, bug, and 2 more (#92)
allcontributors[bot] Dec 1, 2022
4e2d9a0
docs: add pevner-p2 as a contributor for code (#93)
allcontributors[bot] Dec 1, 2022
85154c8
1.3.3 (#96)
chdastolfo Dec 8, 2022
a528b00
docs: add t-a-y-l-o-r as a contributor for code (#97)
allcontributors[bot] Dec 8, 2022
fb9adc2
Readme updated
albcl Jun 20, 2022
2b0689e
Update readme
albcl Jun 18, 2022
1d38403
Readme update
albcl Oct 18, 2022
93938a2
Restructured Readme
albcl Oct 18, 2022
9cc8e82
Merge branch 'master' into feature/duplicate_board_query
albcl Dec 9, 2022
17efb51
Tests improved
albcl Dec 14, 2022
2335617
No need to declare variables again
albcl Dec 14, 2022
3b2c1f0
Better type hints and default values
albcl Dec 14, 2022
0b94fb1
Added missing query parameters
albcl Dec 14, 2022
d42b3ec
Added "duplicate board" query and type hint
albcl Jun 20, 2022
8f445d5
Added extra parameters for the query
albcl Jun 29, 2022
11ac7b5
Added "create board by workspace id"
albcl Jun 18, 2022
5120dbc
Query and tests updated
albcl Oct 18, 2022
5027df3
Fix __email__ typo
chdastolfo Dec 15, 2022
0d9cf2f
Bump certifi from 2021.5.30 to 2022.12.7
dependabot[bot] Dec 9, 2022
246bfc7
Convert README.md to .rst for readthedocs
chdastolfo Jan 5, 2023
5226ae0
docs directory and sphinx setup
chdastolfo Jan 6, 2023
d32dd59
Merge branch 'ProdPerfect:master' into feature/duplicate_board_query
albcl Sep 15, 2023
f5cf788
Updated README
albcl Sep 15, 2023
77c9ca3
fix/ missing query after rebasing
albcl Sep 15, 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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ monday.items.create_item(board_id='12345678', group_id='today', item_name='Do a

- `fetch_items_by_board_id([board_ids])` - Get all items on a board(s). Accepts a comma separated list of board ids.

- `duplicate_board(board_id, duplicate_type)` - Duplicate a board by its id. It requires a duplication type to be chosen (*duplicate_board_with_structure / duplicate_board_with_pulses / duplicate_board_with_pulses_and_updates*).

- `create_board(board_name, board_kind, workspace_id)` - Create board with the given name and kind by (and optional) workspace id.


#### Users Resource (monday.users)
- `fetch_users(**kwargs)` - Fetch user information associated with an account. See Monday API docs for a list of accepted keyword arguments.
Expand Down
76 changes: 62 additions & 14 deletions monday/query_joins.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from monday.resources.types import DuplicateTypes

from monday.utils import monday_json_stringify

Expand Down Expand Up @@ -336,24 +337,71 @@ def get_boards_by_id_query(board_ids):
}''' % board_ids


def get_columns_by_board_query(board_ids):
return '''query
{
boards(ids: %s) {
def duplicate_board_query(
board_id: int,
duplicate_type: DuplicateTypes,
board_name: str = None,
workspace_id: int = None,
folder_id: int = None,
keep_subscribers: bool = None,
) -> str:
board_name = board_name if board_name else ""
workspace_id = workspace_id if workspace_id else None
folder_id = folder_id if folder_id else None
keep_subscribers = keep_subscribers if keep_subscribers else False

params = """board_id: %s, duplicate_type: %s, board_name: \"%s\"""" % (
board_id,
duplicate_type.value,
board_name,
)

if workspace_id:
params += """, workspace_id: %s"""

query = """
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it should be indented once more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean to move it under the workspace_id condition? That condition is meant to only add to the params variable the workspace_id parameter for the query but it's not a mandatory condition for the query.

However, there is a clear issue there because there isn't a value passed for the %s token, and the test didn't catch it because it was expecting to find a 1 and a 2 within the query, but both are included in the board_id value (Its value is 12) That was a really bad test.

I have updated both the query and its test to fix these issues. I wonder if it had something to do with the merge when the branch was like +20 commits behind...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, now that I look at it again I'm not sure what I was talking about, it looks fine... disregard.

Good catch on test, and ty for fixing.

mutation {
duplicate_board(%s) {
board {
id
name
groups {
groups{
id
title
}
columns {
title
id
type
settings_str
}
}
}''' % board_ids
}
}
""" % (
params
)

return query

def duplicate_board_query(board_id: int, duplicate_type: DuplicateTypes):
rhymiz marked this conversation as resolved.
Show resolved Hide resolved
query = """
mutation {
duplicate_board(board_id: %s, duplicate_type: %s) {
board {
id
}
}
}
""" % (
board_id,
duplicate_type.value,
)
return query


def create_board_by_workspace_query(board_name, board_kind, workspace_id = None):
workspace_query = f'workspace_id: {workspace_id}' if workspace_id else ''
query = '''
mutation {
create_board (board_name:"%s", board_kind: %s, %s) {
id
}
}
''' % (board_name, board_kind, workspace_query)
return query


# USER RESOURCE QUERIES
Expand Down
21 changes: 19 additions & 2 deletions monday/resources/boards.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from monday.resources.base import BaseResource
from monday.query_joins import get_boards_query, get_boards_by_id_query, get_board_items_query, \
get_columns_by_board_query
from monday.query_joins import duplicate_board_query, create_board_by_workspace_query, get_boards_query, get_boards_by_id_query, get_board_items_query, get_columns_by_board_query
from monday.resources.types import DuplicateTypes


class BoardResource(BaseResource):
Expand All @@ -22,3 +22,20 @@ def fetch_items_by_board_id(self, board_ids):
def fetch_columns_by_board_id(self, board_ids):
query = get_columns_by_board_query(board_ids)
return self.client.execute(query)

def duplicate_board(
self,
board_id: int,
duplicate_type: DuplicateTypes,
board_name: str = None,
workspace_id: int = None,
folder_id: int = None,
keep_subscribers: bool = None,
):
query = duplicate_board_query(board_id, duplicate_type, board_name, workspace_id, folder_id, keep_subscribers)
return self.client.execute(query)
return self.client.execute(query)

def create_board(self, board_name, board_kind, workspace_id):
query = create_board_by_workspace_query(board_name, board_kind, workspace_id)
return self.client.execute(query)
9 changes: 9 additions & 0 deletions monday/resources/types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from enum import Enum


class DuplicateTypes(Enum):
"""Board duplication types"""

WITH_STRUCTURE = "duplicate_board_with_structure"
WITH_PULSES = "duplicate_board_with_pulses"
WITH_PULSES_AND_UPDATES = "duplicate_board_with_pulses_and_updates"
19 changes: 17 additions & 2 deletions monday/tests/test_board_resource.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from monday.tests.test_case_resource import BaseTestCase
from monday.query_joins import get_boards_query, get_boards_by_id_query, get_board_items_query, \
get_columns_by_board_query
from monday.query_joins import duplicate_board_query, create_board_by_workspace_query, get_boards_query, get_boards_by_id_query, get_board_items_query, get_columns_by_board_query


class BoardTestCase(BaseTestCase):
Expand All @@ -22,3 +21,19 @@ def test_get_board_items_query(self):
def test_get_columns_by_board_query(self):
query = get_columns_by_board_query(board_ids=self.board_id)
self.assertIn(str(self.board_id), query)

def test_duplicate_board_query(self):
query = duplicate_board_query(board_id=self.board_id, duplicate_type=self.duplicate_type)
self.assertIn(str(self.board_id), query)
self.assertNotIn(str(self.duplicate_type), query)
self.assertIn(str(self.duplicate_type.value), query)

def test_create_board_by_workspace_query(self):
query_a = create_board_by_workspace_query(board_name=self.board_name, board_kind=self.board_kind, workspace_id=self.workspace_id)
self.assertIn(str(self.board_name), query_a)
self.assertIn(str(self.board_kind), query_a)
self.assertIn(str(self.workspace_id), query_a)
query_b = create_board_by_workspace_query(board_name=self.board_name, board_kind=self.board_kind)
self.assertIn(str(self.board_name), query_b)
self.assertIn(str(self.board_kind), query_b)
self.assertNotIn(str(self.workspace_id), query_b)
4 changes: 4 additions & 0 deletions monday/tests/test_case_resource.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import unittest

from monday.resources.types import DuplicateTypes


class BaseTestCase(unittest.TestCase):

def setUp(self):
self.group_name = "my_group"
self.item_name = "Nerd"
self.item_id = 24
self.board_name = "my_board"
self.board_id = 12
self.board_kind = "public"
self.duplicate_type = DuplicateTypes.WITH_PULSES
self.group_id = 7
self.column_id = "file_column"
self.user_ids = [1287123, 1230919]
Expand Down