1

various fixes

This commit is contained in:
Evan Pratten 2023-11-03 10:24:35 -04:00
parent 3373a1d01c
commit 1a46f9796c
4 changed files with 67 additions and 19 deletions

View File

@ -23,7 +23,8 @@
branches = branch -a -l -vv branches = branch -a -l -vv
overview = log --all --pretty=format:'%C(green)commit %C(yellow)%h%C(green) by %C(reset)%C(yellow)%aN %C(dim white)(%ar) %n%C(dim white)%S%n%B%n' overview = log --all --pretty=format:'%C(green)commit %C(yellow)%h%C(green) by %C(reset)%C(yellow)%aN %C(dim white)(%ar) %n%C(dim white)%S%n%B%n'
lscommits = ! ( echo -e "Commits\tFile" && git log --pretty=format: --name-only | sed '/^$/d' | sort | uniq -c | sort -g -r ) | less lscommits = ! ( echo -e "Commits\tFile" && git log --pretty=format: --name-only | sed '/^$/d' | sort | uniq -c | sort -g -r ) | less
lsc = lscommits lsc = lscommits
diff-against = diff --merge-base
[filter "lfs"] [filter "lfs"]
clean = git-lfs clean -- %f clean = git-lfs clean -- %f

View File

@ -67,6 +67,19 @@ def get_all_issues() -> List[Dict[str, Any]]:
) )
response.raise_for_status() response.raise_for_status()
issues.extend(response.json()) issues.extend(response.json())
# Get all issues that I have made in other people's repos
response = requests.get(
"https://api.github.com/user/issues",
headers={
"Authorization": f"token {GITHUB_PAT}",
"Accept": "application/vnd.github.raw+json",
"X-GitHub-Api-Version": GITHUB_API_VERSION,
},
params={"state": "open", "per_page": 100, "filter": "subscribed"},
)
response.raise_for_status()
issues.extend(response.json())
# De-dupe issues # De-dupe issues
issues = list({issue["id"]: issue for issue in issues}.values()) issues = list({issue["id"]: issue for issue in issues}.values())

View File

@ -31,7 +31,7 @@ fi
echo -n "Do you want to force debugging for all processes? (y/N)" echo -n "Do you want to force debugging for all processes? (y/N)"
read force_debug read force_debug
if [ "$force_debug" == "y" ]; then if [ "$force_debug" == "y" ]; then
export GURU_DEBUG=1 export GURU_DEBUG=10
fi fi
# Set PYTHONPATH based on the data we learned # Set PYTHONPATH based on the data we learned

View File

@ -42,6 +42,7 @@ class GitLabIssue:
title: str title: str
issue_id: int issue_id: int
global_id: int global_id: int
kind: str
state: IssueState state: IssueState
created: datetime created: datetime
updated: datetime updated: datetime
@ -49,9 +50,21 @@ class GitLabIssue:
reference_string: str reference_string: str
due_date: Optional[datetime] = None due_date: Optional[datetime] = None
def get_fmt_id(self) -> str:
if self.kind == "merge_request":
return f"!{self.global_id}"
return f"#{self.global_id}"
def list_contains_this(self, list_of_ids: List[str]) -> bool:
if self.kind == "issue" and self.global_id in list_of_ids:
return True
return self.get_fmt_id() in [str(x) for x in list_of_ids]
def get_personal_gitlab_issues(user_id: int = MY_USER_ID) -> List[GitLabIssue]: def get_personal_gitlab_issues(user_id: int = MY_USER_ID) -> List[GitLabIssue]:
# Make an API call # Make an API call
issues = []
response = requests.get( response = requests.get(
f"{GITLAB_ENDPOINT}/issues", f"{GITLAB_ENDPOINT}/issues",
params={ params={
@ -62,22 +75,36 @@ def get_personal_gitlab_issues(user_id: int = MY_USER_ID) -> List[GitLabIssue]:
}, },
) )
response.raise_for_status() response.raise_for_status()
issues.extend(response.json())
response = requests.get(
f"{GITLAB_ENDPOINT}/merge_requests",
params={
"assignee_id": user_id,
"private_token": GITLAB_PAT,
"per_page": 100,
"scope": "all",
"state": "opened",
},
)
response.raise_for_status()
issues.extend(response.json())
# Parse the response # Parse the response
output = [] output = []
for issue in response.json(): for issue in issues:
output.append( output.append(
GitLabIssue( GitLabIssue(
title=issue["title"], title=issue["title"],
issue_id=issue["iid"], issue_id=issue["iid"],
global_id=issue["id"], global_id=issue["id"],
kind=issue.get("type", "merge_request").lower(),
state=IssueState(issue["state"]), state=IssueState(issue["state"]),
created=datetime.fromisoformat(issue["created_at"]), created=datetime.fromisoformat(issue["created_at"]),
updated=datetime.fromisoformat(issue["updated_at"]), updated=datetime.fromisoformat(issue["updated_at"]),
web_url=issue["web_url"], web_url=issue["web_url"],
reference_string=issue["references"]["full"], reference_string=issue["references"]["full"],
due_date=datetime.fromisoformat(issue["due_date"]) due_date=datetime.fromisoformat(issue["due_date"])
if issue["due_date"] if issue.get("due_date")
else None, else None,
) )
) )
@ -86,7 +113,7 @@ def get_personal_gitlab_issues(user_id: int = MY_USER_ID) -> List[GitLabIssue]:
def find_or_create_trello_issue_for( def find_or_create_trello_issue_for(
trello_cards: List[Dict[str, Any]], gitlab_issue: GitLabIssue trello_cards: List[Dict[str, Any]], gitlab_issue: GitLabIssue, dry_run: bool = False
) -> TrelloCardId: ) -> TrelloCardId:
# Look for a card that matches the issue # Look for a card that matches the issue
for card in trello_cards: for card in trello_cards:
@ -100,8 +127,8 @@ def find_or_create_trello_issue_for(
metadata = json.loads(desc_first_line.split("`")[1]) metadata = json.loads(desc_first_line.split("`")[1])
# Check if the card matches # Check if the card matches
if metadata.get("ns") == "guru-gitlab" and ( if metadata.get("ns") == "guru-gitlab" and gitlab_issue.list_contains_this(
gitlab_issue.global_id in metadata.get("ids", []) metadata.get("ids", [])
): ):
print(card["labels"], card["idLabels"]) print(card["labels"], card["idLabels"])
logger.info(f"Found matching card {card['id']}") logger.info(f"Found matching card {card['id']}")
@ -110,28 +137,33 @@ def find_or_create_trello_issue_for(
# Build the description # Build the description
card_description = "\n\n".join( card_description = "\n\n".join(
[ [
f"**Sync Metadata:** `{json.dumps({'ns': 'guru-gitlab', 'ids': [gitlab_issue.global_id]})}`", f"**Sync Metadata:** `{json.dumps({'ns': 'guru-gitlab', 'ids': [gitlab_issue.get_fmt_id()]})}`",
f"**GitLab Issue:** [`{gitlab_issue.reference_string}`]({gitlab_issue.web_url})\n", f"**GitLab Issue:** [`{gitlab_issue.reference_string}`]({gitlab_issue.web_url})\n",
"---", "---",
] ]
) )
# Make a new card # Make a new card
return create_card( if not dry_run:
list_id=PERSONAL_TASKS_BOARD.lists["To Do"], return create_card(
name=gitlab_issue.title, list_id=PERSONAL_TASKS_BOARD.lists["To Do"],
description=card_description, name=gitlab_issue.title,
label_ids=[PERSONAL_TASKS_BOARD.tags["GURU"]], description=card_description,
position="top", label_ids=[PERSONAL_TASKS_BOARD.tags["GURU"]],
api_key=TRELLO_API_KEY, position="top",
api_token=TRELLO_API_TOKEN, api_key=TRELLO_API_KEY,
) api_token=TRELLO_API_TOKEN,
)
else:
return "dry-run"
def main() -> int: def main() -> int:
# Handle program arguments # Handle program arguments
ap = argparse.ArgumentParser(description="Syncs issues from GitLab to Trello") ap = argparse.ArgumentParser(description="Syncs issues from GitLab to Trello")
ap.add_argument(
"--dry-run", help="Don't actually make any changes", action="store_true"
)
ap.add_argument( ap.add_argument(
"-v", "--verbose", help="Enable verbose logging", action="store_true" "-v", "--verbose", help="Enable verbose logging", action="store_true"
) )
@ -158,7 +190,9 @@ def main() -> int:
# Handle each issue # Handle each issue
for issue in issues: for issue in issues:
# Find the trello card id for this issue # Find the trello card id for this issue
trello_card_id = find_or_create_trello_issue_for(trello_cards, issue) trello_card_id = find_or_create_trello_issue_for(
trello_cards, issue, dry_run=args.dry_run
)
logger.info(f"GitLab Issue {issue.global_id} is Trello Card {trello_card_id}") logger.info(f"GitLab Issue {issue.global_id} is Trello Card {trello_card_id}")
return 0 return 0