Skip to content
Merged
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
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,6 @@ phabfive-run-dev: phabfive-build ## run phabfive connected to local phorge insta
--add-host=phorge-files.domain.tld:host-gateway \
$(PHABFIVE_CONFIG_MOUNT) \
phabfive $(ARGS)

format: ## format code using ruff
ruff format .
78 changes: 47 additions & 31 deletions phabfive/diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def _validate_credential_type(self, credential):
m = credential[credential_phid]["monogram"]
t = credential[credential_phid]["type"]

raise PhabfiveDataException(f"{m} is not type of 'ssh-generated-key', 'ssh-key-text' or 'token' but type '{t}'")
raise PhabfiveDataException(
f"{m} is not type of 'ssh-generated-key', 'ssh-key-text' or 'token' but type '{t}'"
)

return credential_phid

Expand Down Expand Up @@ -111,12 +113,14 @@ def create_repository(self, name=None, vcs=None, status=None):
if name in repo["fields"]["name"]:
raise PhabfiveDataException(f"Repository {name} already exists")

transactions = self.to_transactions({
"name": name,
"shortName": name,
"vcs": vcs,
"status": status,
})
transactions = self.to_transactions(
{
"name": name,
"shortName": name,
"vcs": vcs,
"status": status,
}
)

new_repo = self.phab.diffusion.repository.edit(
transactions=transactions,
Expand Down Expand Up @@ -151,7 +155,9 @@ def edit_repositories(self, names=None, status=None):
# TODO: Choose a suitable return when the function is being implemented in cli.py
return True

def create_uri(self, repository_name=None, new_uri=None, io=None, display=None, credential=None):
def create_uri(
self, repository_name=None, new_uri=None, io=None, display=None, credential=None
):
"""
Phabfive wrapper that connects to Phabricator and create uri

Expand All @@ -172,10 +178,14 @@ def create_uri(self, repository_name=None, new_uri=None, io=None, display=None,
display = display or "always"

if io not in IO_NEW_URI_CHOICES:
raise PhabfiveConfigException(f"'{io}' is not valid. Valid IO values are 'default', 'observe', 'mirror' or 'never'")
raise PhabfiveConfigException(
f"'{io}' is not valid. Valid IO values are 'default', 'observe', 'mirror' or 'never'"
)

if display not in DISPLAY_CHOICES:
raise PhabfiveConfigException(f"'{display}' is not valid. Valid Display values are 'default', 'always' or 'hidden'")
raise PhabfiveConfigException(
f"'{display}' is not valid. Valid Display values are 'default', 'always' or 'hidden'"
)

repos = self.get_repositories(attachments={"uris": True})

Expand Down Expand Up @@ -225,16 +235,20 @@ def create_uri(self, repository_name=None, new_uri=None, io=None, display=None,
)

if not repository_exist:
raise PhabfiveDataException(f"'{repository_name}' does not exist. Please create a new repository")
raise PhabfiveDataException(
f"'{repository_name}' does not exist. Please create a new repository"
)
# TODO: raise an exception and let CLI handle print and exit

transactions = self.to_transactions({
"repository": repository_phid,
"uri": new_uri,
"io": io,
"display": display,
"credential": credential_phid,
})
transactions = self.to_transactions(
{
"repository": repository_phid,
"uri": new_uri,
"io": io,
"display": display,
"credential": credential_phid,
}
)

try:
self.phab.diffusion.uri.edit(transactions=transactions)
Expand All @@ -243,7 +257,15 @@ def create_uri(self, repository_name=None, new_uri=None, io=None, display=None,

return new_uri

def edit_uri(self, uri=None, io=None, display=None, credential=None, disable=None, object_identifier=None):
def edit_uri(
self,
uri=None,
io=None,
display=None,
credential=None,
disable=None,
object_identifier=None,
):
"""
Phabfive wrapper that connects to Phabricator and edit uri

Expand Down Expand Up @@ -388,7 +410,9 @@ def get_branches(self, repo_id=None, repo_callsign=None, repo_shortname=None):
if resolved:
return self.phab.diffusion.branchquery(repository=resolved)
else:
raise PhabfiveDataException(f"Repository '{repo_shortname}' is not a valid repository")
raise PhabfiveDataException(
f"Repository '{repo_shortname}' is not a valid repository"
)

def print_repositories(self, status=None, url=False):
"""
Expand All @@ -402,11 +426,7 @@ def print_repositories(self, status=None, url=False):
raise PhabfiveDataException("No data or other error")

# filter based on active or inactive status
repos = [
repo
for repo in repos
if repo["fields"]["status"] in status
]
repos = [repo for repo in repos if repo["fields"]["status"] in status]

# sort based on name
repos = sorted(
Expand Down Expand Up @@ -442,9 +462,7 @@ def print_branches(self, repo):
branches = self.get_branches(repo_shortname=repo)

branch_names = sorted(
branch["shortName"]
for branch in branches
if branch["refType"] == "branch"
branch["shortName"] for branch in branches if branch["refType"] == "branch"
)

for branch_name in branch_names:
Expand All @@ -454,9 +472,7 @@ def _resolve_shortname_to_id(self, shortname):
repos = self.get_repositories()

repo_ids = [
repo["id"]
for repo in repos
if repo["fields"]["shortName"] == shortname
repo["id"] for repo in repos if repo["fields"]["shortName"] == shortname
]

return repo_ids[0] if repo_ids else None
22 changes: 17 additions & 5 deletions phabfive/maniphest_transitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ def matches(self, task_transactions, current_column, column_info):
"""
# All conditions must match for the pattern to match
for condition in self.conditions:
if not self._matches_condition(condition, task_transactions, current_column, column_info):
if not self._matches_condition(
condition, task_transactions, current_column, column_info
):
return False
return True

def _matches_condition(self, condition, task_transactions, current_column, column_info):
def _matches_condition(
self, condition, task_transactions, current_column, column_info
):
"""Check if a single condition matches."""
condition_type = condition.get("type")

Expand Down Expand Up @@ -113,9 +117,15 @@ def _matches_from(self, condition, task_transactions, column_info):

# Check direction
if new_col_info:
if direction == "forward" and new_col_info["sequence"] > old_col_info["sequence"]:
if (
direction == "forward"
and new_col_info["sequence"] > old_col_info["sequence"]
):
return True
elif direction == "backward" and new_col_info["sequence"] < old_col_info["sequence"]:
elif (
direction == "backward"
and new_col_info["sequence"] < old_col_info["sequence"]
):
return True

return False
Expand Down Expand Up @@ -283,7 +293,9 @@ def _parse_single_condition(condition_str):

# Patterns with parameters: type:value or type:value:direction
if ":" not in condition_str:
raise PhabfiveException(f"Invalid transition condition syntax: '{condition_str}'")
raise PhabfiveException(
f"Invalid transition condition syntax: '{condition_str}'"
)

parts = condition_str.split(":", 2) # Split into max 3 parts
condition_type = parts[0].strip()
Expand Down
4 changes: 3 additions & 1 deletion phabfive/passphrase.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ def get_secret(self, ids):
log.debug(json.dumps(response["data"], indent=2))

# When Conduit Access is not accepted for Passphrase the "response" will return value "noAPIAccess" in key "material" instead of the secret
api_access_value = response["data"].get(next(iter(response["data"])))["material"]
api_access_value = response["data"].get(next(iter(response["data"])))[
"material"
]
no_api_access = "noAPIAccess" in api_access_value

if no_api_access:
Expand Down
13 changes: 5 additions & 8 deletions phabfive/paste.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ def _convert_ids(self, ids):

return ids_list_int

def create_paste(self, title=None, file=None, language=None, tags=None, subscribers=None):
def create_paste(
self, title=None, file=None, language=None, tags=None, subscribers=None
):
"""
Wrapper that connects to Phabricator and creates paste.

Expand Down Expand Up @@ -68,9 +70,7 @@ def create_paste(self, title=None, file=None, language=None, tags=None, subscrib

# Phabricator does not take None (empty list is ok for projects/subscribers) as a value, therefor only "type" that has valid value can be sent as an argument
transactions = [
item
for item in transactions_values
if None not in item.values()
item for item in transactions_values if None not in item.values()
]

try:
Expand Down Expand Up @@ -119,10 +119,7 @@ def print_pastes(self, ids=None):
raise PhabfiveDataException("No data or other error")

# sort based on title
response = sorted(
pastes,
key=lambda key: key["fields"]["title"]
)
response = sorted(pastes, key=lambda key: key["fields"]["title"])

for item in response:
paste = item["fields"]["title"]
Expand Down
8 changes: 6 additions & 2 deletions phabfive/priority_transitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ def matches(self, priority_transactions, current_priority):
"""
# All conditions must match for the pattern to match
for condition in self.conditions:
if not self._matches_condition(condition, priority_transactions, current_priority):
if not self._matches_condition(
condition, priority_transactions, current_priority
):
return False
return True

Expand Down Expand Up @@ -284,7 +286,9 @@ def _parse_single_condition(condition_str):
)

if len(parts) < 2:
raise PhabfiveException(f"Missing priority name for condition: '{condition_str}'")
raise PhabfiveException(
f"Missing priority name for condition: '{condition_str}'"
)

priority_name = parts[1].strip()
if not priority_name:
Expand Down
Loading