-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor Linear helpers into package #83
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
Merged
redreceipt
merged 1 commit into
main
from
codex/create-linear-package-and-reorganize-code
Jul 30, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import os | ||
| from datetime import datetime | ||
| from functools import lru_cache | ||
|
|
||
| from dotenv import load_dotenv | ||
| from gql import Client | ||
| from gql.transport.aiohttp import AIOHTTPTransport | ||
|
|
||
| load_dotenv() | ||
|
|
||
|
|
||
| def _compute_assignee_time_to_fix(issue, assignee_name): | ||
| """Return days between last assignment to `assignee_name` and completion.""" | ||
| history = issue.get("history", {}).get("edges", []) | ||
| last_assigned = None | ||
| for edge in history: | ||
| node = edge.get("node", {}) | ||
| to_assignee = node.get("toAssignee") | ||
| if not to_assignee: | ||
| continue | ||
| if to_assignee.get("displayName") == assignee_name: | ||
| updated = node.get("updatedAt") | ||
| if updated and (last_assigned is None or updated > last_assigned): | ||
| last_assigned = updated | ||
| if not last_assigned: | ||
| return None | ||
| completed_at = issue.get("completedAt") | ||
| if not completed_at: | ||
| return None | ||
| try: | ||
| completed_dt = datetime.strptime(completed_at, "%Y-%m-%dT%H:%M:%S.%fZ") | ||
| assigned_dt = datetime.strptime(last_assigned, "%Y-%m-%dT%H:%M:%S.%fZ") | ||
| return (completed_dt - assigned_dt).days | ||
| except ValueError: | ||
| return None | ||
|
|
||
|
|
||
| @lru_cache(maxsize=1) | ||
| def _get_client(): | ||
| headers = {"Authorization": os.getenv("LINEAR_API_KEY")} | ||
| transport = AIOHTTPTransport( | ||
| url="https://api.linear.app/graphql", | ||
| headers=headers, | ||
| ) | ||
| return Client(transport=transport, fetch_schema_from_transport=True) | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| from gql import gql | ||
|
|
||
| from .client import _get_client | ||
|
|
||
|
|
||
| def get_projects(): | ||
| """Return all Linear projects under the Apollos team, ordered by name.""" | ||
| query = gql( | ||
| """ | ||
| query { | ||
| teams(filter: { name: { eq: \"Apollos\" } }, first: 1) { | ||
| nodes { | ||
| projects(first: 50) { | ||
| nodes { | ||
| id | ||
| name | ||
| url | ||
| health | ||
| status { | ||
| name | ||
| } | ||
| startDate | ||
| targetDate | ||
| lead { | ||
| displayName | ||
| } | ||
| initiatives(first: 50) { | ||
| nodes { | ||
| id | ||
| name | ||
| } | ||
| } | ||
| members(first: 50) { | ||
| nodes { | ||
| displayName | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| """ | ||
| ) | ||
| data = _get_client().execute(query) | ||
| teams = data.get("teams", {}).get("nodes", []) or [] | ||
| if not teams: | ||
| return [] | ||
| projects = teams[0].get("projects", {}).get("nodes", []) or [] | ||
| sorted_projects = sorted(projects, key=lambda project: project.get("name", "")) | ||
| for project in sorted_projects: | ||
| nodes = project.get("members", {}).get("nodes", []) | ||
| project["members"] = [m["displayName"] for m in nodes if m.get("displayName")] | ||
| return sorted_projects | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The team name "Apollos" is hardcoded in the query. Consider making this configurable through a parameter or environment variable to improve flexibility and maintainability.