mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
fixed linting error and formatting
This commit is contained in:
@@ -8,7 +8,7 @@ from .projects import LinearSearchProjectsBlock
|
||||
|
||||
__all__ = [
|
||||
"LinearCreateCommentBlock",
|
||||
"LinearCreateIssueBlock",
|
||||
"LinearCreateIssueBlock",
|
||||
"LinearSearchIssuesBlock",
|
||||
"LinearSearchProjectsBlock",
|
||||
]
|
||||
]
|
||||
|
||||
@@ -3,13 +3,9 @@ from __future__ import annotations
|
||||
import json
|
||||
from typing import Any, Dict, Optional, Union
|
||||
|
||||
from backend.sdk import OAuth2Credentials, APIKeyCredentials, Requests
|
||||
from .models import (
|
||||
CreateCommentResponse,
|
||||
CreateIssueResponse,
|
||||
Issue,
|
||||
Project,
|
||||
)
|
||||
from backend.sdk import APIKeyCredentials, OAuth2Credentials, Requests
|
||||
|
||||
from .models import CreateCommentResponse, CreateIssueResponse, Issue, Project
|
||||
|
||||
|
||||
class LinearAPIException(Exception):
|
||||
@@ -39,9 +35,13 @@ class LinearClient:
|
||||
}
|
||||
if credentials:
|
||||
if isinstance(credentials, OAuth2Credentials):
|
||||
headers["Authorization"] = f"Bearer {credentials.access_token.get_secret_value()}"
|
||||
headers["Authorization"] = (
|
||||
f"Bearer {credentials.access_token.get_secret_value()}"
|
||||
)
|
||||
elif isinstance(credentials, APIKeyCredentials):
|
||||
headers["Authorization"] = f"{credentials.api_key.get_secret_value()}"
|
||||
headers["Authorization"] = (
|
||||
f"{credentials.api_key.get_secret_value()}"
|
||||
)
|
||||
|
||||
self._requests = Requests(
|
||||
extra_headers=headers,
|
||||
|
||||
@@ -3,7 +3,9 @@ Shared configuration for all Linear blocks using the new SDK pattern.
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from backend.sdk import BlockCostType, ProviderBuilder
|
||||
|
||||
from ._oauth import LinearOAuthHandler
|
||||
|
||||
# Check if Linear OAuth is configured
|
||||
@@ -17,12 +19,11 @@ builder = ProviderBuilder("linear").with_base_cost(1, BlockCostType.RUN)
|
||||
# Add OAuth support if configured
|
||||
if LINEAR_OAUTH_IS_CONFIGURED:
|
||||
builder = builder.with_oauth(
|
||||
LinearOAuthHandler,
|
||||
scopes=["read", "write", "issues:create", "comments:create"]
|
||||
LinearOAuthHandler, scopes=["read", "write", "issues:create", "comments:create"]
|
||||
)
|
||||
|
||||
# Add API key support as a fallback
|
||||
builder = builder.with_api_key("LINEAR_API_KEY", "Linear API Key")
|
||||
|
||||
# Build the provider
|
||||
linear = builder.build()
|
||||
linear = builder.build()
|
||||
|
||||
@@ -7,9 +7,9 @@ from typing import Optional
|
||||
from urllib.parse import urlencode
|
||||
|
||||
from backend.sdk import (
|
||||
APIKeyCredentials,
|
||||
BaseOAuthHandler,
|
||||
OAuth2Credentials,
|
||||
APIKeyCredentials,
|
||||
ProviderName,
|
||||
Requests,
|
||||
SecretStr,
|
||||
@@ -18,6 +18,7 @@ from backend.sdk import (
|
||||
|
||||
class LinearAPIException(Exception):
|
||||
"""Exception for Linear API errors."""
|
||||
|
||||
def __init__(self, message: str, status_code: int):
|
||||
super().__init__(message)
|
||||
self.status_code = status_code
|
||||
@@ -106,9 +107,7 @@ class LinearOAuthHandler(BaseOAuthHandler):
|
||||
**params,
|
||||
}
|
||||
|
||||
headers = {
|
||||
"Content-Type": "application/x-www-form-urlencoded"
|
||||
}
|
||||
headers = {"Content-Type": "application/x-www-form-urlencoded"}
|
||||
response = await Requests().post(
|
||||
self.token_url, data=request_body, headers=headers
|
||||
)
|
||||
@@ -130,9 +129,7 @@ class LinearOAuthHandler(BaseOAuthHandler):
|
||||
new_credentials = OAuth2Credentials(
|
||||
provider=self.PROVIDER_NAME,
|
||||
title=current_credentials.title if current_credentials else None,
|
||||
username=token_data.get("user", {}).get(
|
||||
"name", "Unknown User"
|
||||
),
|
||||
username=token_data.get("user", {}).get("name", "Unknown User"),
|
||||
access_token=token_data["access_token"],
|
||||
scopes=token_data["scope"].split(
|
||||
","
|
||||
@@ -174,4 +171,4 @@ class LinearOAuthHandler(BaseOAuthHandler):
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error fetching username: {e}")
|
||||
return None
|
||||
return None
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
from backend.sdk import (
|
||||
APIKeyCredentials,
|
||||
Block,
|
||||
BlockCategory,
|
||||
BlockOutput,
|
||||
BlockSchema,
|
||||
CredentialsMetaInput,
|
||||
OAuth2Credentials,
|
||||
SchemaField,
|
||||
String,
|
||||
OAuth2Credentials,
|
||||
APIKeyCredentials,
|
||||
CredentialsMetaInput,
|
||||
)
|
||||
|
||||
from ._api import LinearAPIException, LinearClient
|
||||
from .models import CreateCommentResponse
|
||||
from ._config import linear
|
||||
from .models import CreateCommentResponse
|
||||
|
||||
|
||||
class LinearCreateCommentBlock(Block):
|
||||
@@ -58,7 +59,7 @@ class LinearCreateCommentBlock(Block):
|
||||
input_data: Input,
|
||||
*,
|
||||
credentials: OAuth2Credentials | APIKeyCredentials,
|
||||
**kwargs
|
||||
**kwargs,
|
||||
) -> BlockOutput:
|
||||
"""Execute the comment creation"""
|
||||
try:
|
||||
@@ -74,4 +75,4 @@ class LinearCreateCommentBlock(Block):
|
||||
except LinearAPIException as e:
|
||||
yield "error", str(e)
|
||||
except Exception as e:
|
||||
yield "error", f"Unexpected error: {str(e)}"
|
||||
yield "error", f"Unexpected error: {str(e)}"
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
from backend.sdk import (
|
||||
APIKeyCredentials,
|
||||
Block,
|
||||
BlockCategory,
|
||||
BlockOutput,
|
||||
BlockSchema,
|
||||
CredentialsMetaInput,
|
||||
OAuth2Credentials,
|
||||
SchemaField,
|
||||
String,
|
||||
OAuth2Credentials,
|
||||
APIKeyCredentials,
|
||||
CredentialsMetaInput,
|
||||
)
|
||||
|
||||
from ._api import LinearAPIException, LinearClient
|
||||
from .models import CreateIssueResponse, Issue
|
||||
from ._config import linear
|
||||
from .models import CreateIssueResponse, Issue
|
||||
|
||||
|
||||
class LinearCreateIssueBlock(Block):
|
||||
@@ -23,7 +24,9 @@ class LinearCreateIssueBlock(Block):
|
||||
required_scopes={"read", "issues:create"},
|
||||
)
|
||||
title: String = SchemaField(description="Title of the issue")
|
||||
description: String = SchemaField(description="Description of the issue", default="")
|
||||
description: String = SchemaField(
|
||||
description="Description of the issue", default=""
|
||||
)
|
||||
team_name: String = SchemaField(
|
||||
description="Name of the team to create the issue on"
|
||||
)
|
||||
@@ -86,7 +89,7 @@ class LinearCreateIssueBlock(Block):
|
||||
input_data: Input,
|
||||
*,
|
||||
credentials: OAuth2Credentials | APIKeyCredentials,
|
||||
**kwargs
|
||||
**kwargs,
|
||||
) -> BlockOutput:
|
||||
"""Execute the issue creation"""
|
||||
try:
|
||||
@@ -147,7 +150,7 @@ class LinearSearchIssuesBlock(Block):
|
||||
input_data: Input,
|
||||
*,
|
||||
credentials: OAuth2Credentials | APIKeyCredentials,
|
||||
**kwargs
|
||||
**kwargs,
|
||||
) -> BlockOutput:
|
||||
"""Execute the issue search"""
|
||||
try:
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
from backend.sdk import (
|
||||
APIKeyCredentials,
|
||||
Block,
|
||||
BlockCategory,
|
||||
BlockOutput,
|
||||
BlockSchema,
|
||||
CredentialsMetaInput,
|
||||
OAuth2Credentials,
|
||||
SchemaField,
|
||||
String,
|
||||
OAuth2Credentials,
|
||||
APIKeyCredentials,
|
||||
CredentialsMetaInput,
|
||||
)
|
||||
|
||||
from ._api import LinearAPIException, LinearClient
|
||||
from .models import Project
|
||||
from ._config import linear
|
||||
from .models import Project
|
||||
|
||||
|
||||
class LinearSearchProjectsBlock(Block):
|
||||
@@ -53,7 +54,7 @@ class LinearSearchProjectsBlock(Block):
|
||||
input_data: Input,
|
||||
*,
|
||||
credentials: OAuth2Credentials | APIKeyCredentials,
|
||||
**kwargs
|
||||
**kwargs,
|
||||
) -> BlockOutput:
|
||||
"""Execute the project search"""
|
||||
try:
|
||||
|
||||
@@ -134,22 +134,27 @@ export default function UserIntegrationsPage() {
|
||||
}
|
||||
|
||||
const allCredentials = providers
|
||||
? Object.values(providers).flatMap((provider) =>
|
||||
provider.savedCredentials
|
||||
.filter((cred) => !hiddenCredentials.includes(cred.id))
|
||||
.map((credentials) => ({
|
||||
...credentials,
|
||||
provider: provider.provider,
|
||||
providerName: provider.providerName,
|
||||
ProviderIcon: providerIcons[provider.provider] || KeyIcon,
|
||||
TypeIcon: {
|
||||
oauth2: IconUser,
|
||||
api_key: IconKey,
|
||||
user_password: IconKey,
|
||||
host_scoped: IconKey,
|
||||
}[credentials.type],
|
||||
})),
|
||||
)
|
||||
? Object.values(providers)
|
||||
.filter(
|
||||
(provider): provider is NonNullable<typeof provider> =>
|
||||
provider != null,
|
||||
)
|
||||
.flatMap((provider) =>
|
||||
provider.savedCredentials
|
||||
.filter((cred) => !hiddenCredentials.includes(cred.id))
|
||||
.map((credentials) => ({
|
||||
...credentials,
|
||||
provider: provider.provider,
|
||||
providerName: provider.providerName,
|
||||
ProviderIcon: providerIcons[provider.provider] || KeyIcon,
|
||||
TypeIcon: {
|
||||
oauth2: IconUser,
|
||||
api_key: IconKey,
|
||||
user_password: IconKey,
|
||||
host_scoped: IconKey,
|
||||
}[credentials.type],
|
||||
})),
|
||||
)
|
||||
: [];
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user