Compare commits

..

10 Commits

Author SHA1 Message Date
78a897fa66 change methods 2025-07-15 23:30:30 -05:00
8880332d51 change method 2025-07-15 23:20:21 -05:00
095dc9afe9 fix wrong issues 2025-07-15 23:10:50 -05:00
f7417db29b fix method name 2025-07-15 23:09:50 -05:00
1ad184b81f change param 2025-07-15 23:00:57 -05:00
0c7b4ebb53 ignore pulls in issues 2025-07-15 22:51:23 -05:00
db29e78093 change logging levels 2025-07-15 22:40:40 -05:00
606dd2f9ce remove int cast 2025-07-15 22:36:05 -05:00
c17e56ee2d replace add with append 2025-07-15 22:31:18 -05:00
9ac7dd29e3 remove owner 2025-07-15 22:30:53 -05:00
2 changed files with 29 additions and 46 deletions

View File

@@ -103,14 +103,11 @@ class Gitea:
def get_issues( def get_issues(
self, self,
owner: str,
repository: str, repository: str,
): ):
path = f"/repos/{owner}/{repository}/issues" path = f"/repos/{repository}/issues"
params = {"state": "open"} params = {"state": "open", "type": "issues"}
self.logger.debug(f">> Path used to get issues: {path}") self.logger.debug(f">> Path used to get issues: {path}")
self.logger.debug(f">> Owner: {owner}")
self.logger.debug(f">> Repository: {repository}")
result = self.requests_get(path, params) result = self.requests_get(path, params)
self.logger.debug(">> Gitea response: %s", result) self.logger.debug(">> Gitea response: %s", result)
@@ -118,53 +115,46 @@ class Gitea:
def get_pull_requests( def get_pull_requests(
self, self,
owner: str,
repository: str, repository: str,
): ):
path = f"/repos/{owner}/{repository}/pulls" path = f"/repos/{repository}/pulls"
params = {"state": "open"} params = {"state": "open"}
self.logger.debug(f">> Path used to get pull requests: {path}") self.logger.debug(f">> Path used to get pull requests: {path}")
self.logger.debug(f">> Owner: {owner}")
self.logger.debug(f">> Repository: {repository}")
result = self.requests_get(path, params) result = self.requests_get(path, params)
self.logger.debug(">> Gitea response: %s", result) self.logger.debug(">> Gitea response: %s", result)
return result return result
def update_issue_labels( def post_issue_labels(
self, self,
issue_number: int, issue_number: int,
labels: list, labels: list,
owner: str,
repository: str, repository: str,
): ):
path = f"/repos/{owner}/{repository}/issues/{issue_number}/labels" path = f"/repos/{repository}/issues/{issue_number}/labels"
data = {"labels": labels} params = {"labels": [labels]}
self.logger.debug(f">> Path used to update issue label: {path}") self.logger.debug(f">> Path used to update issue label: {path}")
result = self.requests_post(path, data) result = self.requests_post(path, params)
if "id" in result: if "id" in result:
self.logger.info(">> Successfully added label") self.logger.info(">> Successfully added label")
self.logger.debug(">> Gitea response: %s", result) self.logger.debug(">> Gitea response: %s", result)
else: else:
self.logger.error(result["message"]) self.logger.error(result["message"])
# raise Exception("User not created... (gitea: %s)" % result["message"])
def update_pull_request_labels( def post_pull_request_labels(
self, self,
pull_request_number: int, pull_request_number: int,
labels: list, labels: list,
owner: str,
repository: str, repository: str,
): ):
path = f"/repos/{owner}/{repository}/pulls/{pull_request_number}/labels" path = f"/repos/{repository}/pulls/{pull_request_number}"
data = {"labels": labels} params = {"labels": [labels]}
self.logger.debug(f">> Path used to update pull request labels: {path}") self.logger.debug(f">> Path used to update pull request labels: {path}")
result = self.requests_post(path, data) result = self.requests_post(path, params)
if "id" in result: if "id" in result:
self.logger.info(">> Successfully added label") self.logger.info(">> Successfully added label")
self.logger.debug(">> Gitea response: %s", result) self.logger.debug(">> Gitea response: %s", result)
else: else:
self.logger.error(result["message"]) self.logger.error(result["message"])
# raise Exception("User not created... (gitea: %s)" % result["message"])

View File

@@ -14,7 +14,6 @@ def main():
# --- Get configuration from environment variables --- # --- Get configuration from environment variables ---
try: try:
instance_url = os.environ["INSTANCE_URL"].rstrip("/") instance_url = os.environ["INSTANCE_URL"].rstrip("/")
owner = os.environ["OWNER"]
repository = os.environ["REPOSITORY"] repository = os.environ["REPOSITORY"]
token = os.environ["TOKEN"] token = os.environ["TOKEN"]
log_level = os.environ.get("LOG_LEVEL", "INFO").upper() log_level = os.environ.get("LOG_LEVEL", "INFO").upper()
@@ -50,7 +49,7 @@ def main():
# --- Fetch issues --- # --- Fetch issues ---
logger.info(f">> Fetching issues ...") logger.info(f">> Fetching issues ...")
issues = gitea.get_issues(owner=owner, repository=repository) issues = gitea.get_issues(repository=repository)
# --- Process issues --- # --- Process issues ---
if len(issues) < 1: if len(issues) < 1:
@@ -67,23 +66,22 @@ def main():
days=int(issue_stale_days) days=int(issue_stale_days)
) )
issue_current_labels = {label["name"] for label in issue.get("labels", [])} issue_current_labels = {label["name"] for label in issue.get("labels", [])}
issue_update_labels = list(issue_current_labels)
logger.debug(f">> Issue has the following labels: {issue_current_labels}") logger.debug(f">> Issue has the following labels: {issue_current_labels}")
# -- Check required -- # -- Check required --
if (not issue_required_tag == None) and ( if (not issue_required_tag == None) and (
not int(issue_required_tag) in issue_current_labels not issue_required_tag in issue_current_labels
): ):
logger.debug( logger.info(
f">> Skipping issue #{issue["number"]} because it does not have the required ('{issue_required_tag}') tag" f">> Skipping issue #{issue["number"]} because it does not have the required ('{issue_required_tag}') tag"
) )
continue continue
# -- Check exclude -- # -- Check exclude --
if (not issue_exclude_tag == None) and ( if (not issue_exclude_tag == None) and (
int(issue_exclude_tag) in issue_current_labels issue_exclude_tag in issue_current_labels
): ):
logger.debug( logger.info(
f">> Skipping issue #{issue["number"]} because it has the exclude ('{issue_exclude_tag}') tag" f">> Skipping issue #{issue["number"]} because it has the exclude ('{issue_exclude_tag}') tag"
) )
continue continue
@@ -97,7 +95,7 @@ def main():
) )
if issue_stale_tag in issue_current_labels: if issue_stale_tag in issue_current_labels:
logger.debug( logger.info(
f">> Skipping issue #{issue["number"]} because it already has the stale ('{issue_stale_tag}') tag" f">> Skipping issue #{issue["number"]} because it already has the stale ('{issue_stale_tag}') tag"
) )
continue continue
@@ -105,12 +103,10 @@ def main():
logger.info( logger.info(
f">> Will tag issue #{issue["number"]} with '{issue_stale_tag}'" f">> Will tag issue #{issue["number"]} with '{issue_stale_tag}'"
) )
issue_update_labels.add(issue_stale_tag)
gitea.update_issue_labels( gitea.post_issue_labels(
issue_number=issue["number"], issue_number=issue["number"],
labels=issue_update_labels, labels=issue_stale_tag,
owner=owner,
repository=repository, repository=repository,
) )
@@ -119,7 +115,7 @@ def main():
logger.info(">> Finished processing issues") logger.info(">> Finished processing issues")
# --- Fetch pull requests --- # --- Fetch pull requests ---
pull_requests = gitea.get_pull_requests(owner=owner, repository=repository) pull_requests = gitea.get_pull_requests(repository=repository)
# --- Process pull requests --- # --- Process pull requests ---
if len(pull_requests) < 1: if len(pull_requests) < 1:
@@ -138,25 +134,24 @@ def main():
pull_request_current_labels = { pull_request_current_labels = {
label["name"] for label in pull_request.get("labels", []) label["name"] for label in pull_request.get("labels", [])
} }
pull_request_update_labels = list(pull_request_current_labels)
logger.debug( logger.debug(
f">> Pull request has the following labels: {issue_current_labels}" f">> Pull request has the following labels: {pull_request_current_labels}"
) )
# -- Check required -- # -- Check required --
if (not pull_request_required_tag == None) and ( if (not pull_request_required_tag == None) and (
not int(pull_request_required_tag) in pull_request_current_labels not pull_request_required_tag in pull_request_current_labels
): ):
logger.debug( logger.info(
f">> Skipping pull request #{pull_request["number"]} because it does not have the required ('{pull_request_required_tag}') tag" f">> Skipping pull request #{pull_request["number"]} because it does not have the required ('{pull_request_required_tag}') tag"
) )
continue continue
# -- Check exclude -- # -- Check exclude --
if (not pull_request_exclude_tag == None) and ( if (not pull_request_exclude_tag == None) and (
int(pull_request_exclude_tag) in pull_request_current_labels pull_request_exclude_tag in pull_request_current_labels
): ):
logger.debug( logger.info(
f">> Skipping pull request #{pull_request["number"]} because it has the exclude ('{pull_request_exclude_tag}') tag" f">> Skipping pull request #{pull_request["number"]} because it has the exclude ('{pull_request_exclude_tag}') tag"
) )
continue continue
@@ -170,7 +165,7 @@ def main():
) )
if pull_request_stale_tag in pull_request_current_labels: if pull_request_stale_tag in pull_request_current_labels:
logger.debug( logger.info(
f">> Skipping pull request #{pull_request["number"]} because it already has the stale ('{pull_request_stale_tag}') tag" f">> Skipping pull request #{pull_request["number"]} because it already has the stale ('{pull_request_stale_tag}') tag"
) )
continue continue
@@ -178,16 +173,14 @@ def main():
logger.info( logger.info(
f">> Will tag pull request #{pull_request["number"]} with '{pull_request_stale_tag}'" f">> Will tag pull request #{pull_request["number"]} with '{pull_request_stale_tag}'"
) )
pull_request_update_labels.add(pull_request_stale_tag)
gitea.update_pull_requests( gitea.post_pull_request_labels(
pull_request_number=pull_request["number"], pull_request_number=pull_request["number"],
labels=pull_request_update_labels, labels=pull_request_stale_tag,
owner=owner,
repository=repository, repository=repository,
) )
logger.info(f">> Finished pull request #{issue["number"]}") logger.info(f">> Finished pull request #{pull_request["number"]}")
logger.info(">> Finished processing pull requests") logger.info(">> Finished processing pull requests")