Skip to content
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

feat(blocks): Add blocks for GitHub checks & statuses #9271

Merged
merged 25 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f9db2f0
feat: checks for github
ntindle Jan 10, 2025
355c6d4
feat: better parsing
ntindle Jan 12, 2025
b6689db
Revert "feat: better parsing"
ntindle Jan 15, 2025
0735a32
Merge branch 'master' into github-checks
ntindle Jan 15, 2025
4e8834a
Update checks.py
ntindle Jan 15, 2025
d654544
Merge branch 'dev' into github-checks
ntindle Jan 18, 2025
5ef3419
fix: lint
ntindle Jan 18, 2025
4bd5b89
fix: inputs i guess
ntindle Jan 18, 2025
b7fdb0b
fix: checks vibes were weird
ntindle Jan 18, 2025
1fae384
Merge branch 'dev' into github-checks
ntindle Jan 21, 2025
43892db
feat: move to statuses from checks and get statuses functional w/ API…
ntindle Jan 23, 2025
9e50c8e
feat: logic block required for agent
ntindle Jan 23, 2025
ec9cecf
Merge branch 'dev' into github-checks
ntindle Jan 23, 2025
2382451
Merge branch 'github-checks' of https://github.com/Significant-Gravit…
ntindle Jan 24, 2025
dca3c21
fix(blocks): pr changes
ntindle Jan 24, 2025
d002323
fix: lint
ntindle Jan 24, 2025
c10fc8f
fix: remove bytes test
ntindle Jan 24, 2025
d75ff6a
Merge branch 'dev' into github-checks
ntindle Jan 24, 2025
535673e
Merge branch 'dev' into github-checks
ntindle Jan 24, 2025
c15520e
Merge branch 'dev' into github-checks
ntindle Jan 24, 2025
802f6c2
Merge branch 'dev' into github-checks
ntindle Jan 26, 2025
30931fe
Merge branch 'dev' into github-checks
ntindle Jan 27, 2025
546c7a0
Merge branch 'dev' into github-checks
ntindle Jan 28, 2025
795664e
ref: better naming of the finegrained credentials
ntindle Jan 28, 2025
5d926e0
Merge branch 'dev' into github-checks
aarushik93 Jan 28, 2025
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
80 changes: 80 additions & 0 deletions autogpt_platform/backend/backend/blocks/branching.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,83 @@ def run(self, input_data: Input, **kwargs) -> BlockOutput:
yield "yes_output", yes_value
else:
yield "no_output", no_value


class IfInputMatchesBlock(Block):
ntindle marked this conversation as resolved.
Show resolved Hide resolved
class Input(BlockSchema):
input: Any = SchemaField(
description="The input to match against",
placeholder="For example: 10 or 'hello' or True",
)
value: Any = SchemaField(
description="The value to output if the input matches",
placeholder="For example: 'Greater' or 20 or False",
)
yes_value: Any = SchemaField(
description="The value to output if the input matches",
placeholder="For example: 'Greater' or 20 or False",
default=None,
)
no_value: Any = SchemaField(
description="The value to output if the input does not match",
placeholder="For example: 'Greater' or 20 or False",
default=None,
)

class Output(BlockSchema):
result: bool = SchemaField(
description="The result of the condition evaluation (True or False)"
)
yes_output: Any = SchemaField(
description="The output value if the condition is true"
)
no_output: Any = SchemaField(
description="The output value if the condition is false"
)

def __init__(self):
super().__init__(
id="6dbbc4b3-ca6c-42b6-b508-da52d23e13f2",
input_schema=IfInputMatchesBlock.Input,
output_schema=IfInputMatchesBlock.Output,
description="Handles conditional logic based on comparison operators",
categories={BlockCategory.LOGIC},
test_input=[
{
"input": 10,
"value": 10,
"yes_value": "Greater",
"no_value": "Not greater",
},
{
"input": 10,
"value": 20,
"yes_value": "Greater",
"no_value": "Not greater",
},
{
"input": 10,
"value": None,
"yes_value": "Yes",
"no_value": "No",
},
],
test_output=[
("result", True),
("yes_output", "Greater"),
("result", False),
("no_output", "Not greater"),
("result", False),
("no_output", "No"),
# ("result", True),
# ("yes_output", "Yes"),
],
)

def run(self, input_data: Input, **kwargs) -> BlockOutput:
if input_data.input == input_data.value or input_data.input is input_data.value:
yield "result", True
yield "yes_output", input_data.yes_value
else:
yield "result", False
yield "no_output", input_data.no_value
10 changes: 8 additions & 2 deletions autogpt_platform/backend/backend/blocks/github/_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from urllib.parse import urlparse

from backend.blocks.github._auth import GithubCredentials
from backend.blocks.github._auth import (
GithubCredentials,
GithubFineGrainedAPICredentials,
)
from backend.util.request import Requests


Expand Down Expand Up @@ -35,7 +38,10 @@ def _get_headers(credentials: GithubCredentials) -> dict[str, str]:
}


def get_api(credentials: GithubCredentials, convert_urls: bool = True) -> Requests:
def get_api(
credentials: GithubCredentials | GithubFineGrainedAPICredentials,
convert_urls: bool = True,
) -> Requests:
return Requests(
trusted_origins=["https://api.github.com", "https://github.com"],
extra_url_validator=_convert_to_api_url if convert_urls else None,
Expand Down
30 changes: 30 additions & 0 deletions autogpt_platform/backend/backend/blocks/github/_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
Literal["api_key", "oauth2"] if GITHUB_OAUTH_IS_CONFIGURED else Literal["api_key"],
]

GithubFineGrainedAPICredentials = APIKeyCredentials
GithubFineGrainedAPICredentialsInput = CredentialsMetaInput[
Literal[ProviderName.GITHUB], Literal["api_key"]
]


def GithubCredentialsField(scope: str) -> GithubCredentialsInput:
"""
Expand All @@ -37,6 +42,16 @@ def GithubCredentialsField(scope: str) -> GithubCredentialsInput:
)


def GithubFineGrainedAPICredentialsField(
scope: str,
) -> GithubFineGrainedAPICredentialsInput:
return CredentialsField(
required_scopes={scope},
description="The GitHub integration can be used with OAuth, "
"or any API key with sufficient permissions for the blocks it is used on.",
)


TEST_CREDENTIALS = APIKeyCredentials(
id="01234567-89ab-cdef-0123-456789abcdef",
provider="github",
Expand All @@ -50,3 +65,18 @@ def GithubCredentialsField(scope: str) -> GithubCredentialsInput:
"type": TEST_CREDENTIALS.type,
"title": TEST_CREDENTIALS.type,
}

TEST_FINE_GRAINED_CREDENTIALS = APIKeyCredentials(
id="01234567-89ab-cdef-0123-456789abcdef",
provider="github",
api_key=SecretStr("mock-github-api-key"),
title="Mock GitHub API key",
expires_at=None,
)

TEST_FINE_GRAINED_CREDENTIALS_INPUT = {
"provider": TEST_FINE_GRAINED_CREDENTIALS.provider,
"id": TEST_FINE_GRAINED_CREDENTIALS.id,
"type": TEST_FINE_GRAINED_CREDENTIALS.type,
"title": TEST_FINE_GRAINED_CREDENTIALS.type,
}
Loading
Loading