-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(autofix): Endpoint to get the autofix state from a pr id (#696)
Introduces the `/v1/automation/autofix/state/pr` endpoint which will return an autofix fix state for a git provider + pr id. We store a mappings for that as a db table when prs are created. This endpoint will be used for the github webhook flows.
- Loading branch information
Showing
10 changed files
with
259 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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,47 @@ | ||
"""Migration | ||
Revision ID: ab24602a9f68 | ||
Revises: b6cca7c6d99c | ||
Create Date: 2024-05-10 21:42:27.125458 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "ab24602a9f68" | ||
down_revision = "b6cca7c6d99c" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
"autofix_pr_id_to_run_id", | ||
sa.Column("id", sa.Integer(), nullable=False), | ||
sa.Column("provider", sa.String(), nullable=False), | ||
sa.Column("pr_id", sa.BigInteger(), nullable=False), | ||
sa.Column("run_id", sa.Integer(), nullable=False), | ||
sa.ForeignKeyConstraint( | ||
["run_id"], | ||
["run_state.id"], | ||
), | ||
sa.PrimaryKeyConstraint("id"), | ||
sa.UniqueConstraint("provider", "pr_id", "run_id"), | ||
) | ||
with op.batch_alter_table("autofix_pr_id_to_run_id", schema=None) as batch_op: | ||
batch_op.create_index( | ||
"ix_autofix_pr_id_to_run_id_provider_pr_id", ["provider", "pr_id"], unique=False | ||
) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table("autofix_pr_id_to_run_id", schema=None) as batch_op: | ||
batch_op.drop_index("ix_autofix_pr_id_to_run_id_provider_pr_id") | ||
|
||
op.drop_table("autofix_pr_id_to_run_id") | ||
# ### end Alembic commands ### |
This file contains 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 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 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 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 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 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 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 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 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,33 @@ | ||
import unittest | ||
|
||
from johen import generate | ||
|
||
from seer.automation.autofix.models import AutofixContinuation | ||
from seer.automation.autofix.tasks import get_autofix_state_from_pr_id | ||
from seer.db import DbPrIdToAutofixRunIdMapping, DbRunState, Session | ||
|
||
|
||
class TestGetStateFromPr(unittest.TestCase): | ||
def test_successful_state_mapping(self): | ||
state = next(generate(AutofixContinuation)) | ||
with Session() as session: | ||
session.add(DbRunState(id=1, group_id=1, value=state.model_dump(mode="json"))) | ||
session.flush() | ||
session.add(DbPrIdToAutofixRunIdMapping(provider="test", pr_id=1, run_id=1)) | ||
session.commit() | ||
|
||
retrieved_state = get_autofix_state_from_pr_id("test", 1) | ||
self.assertIsNotNone(retrieved_state) | ||
if retrieved_state is not None: | ||
self.assertEqual(retrieved_state.get(), state) | ||
|
||
def test_no_state_mapping(self): | ||
state = next(generate(AutofixContinuation)) | ||
with Session() as session: | ||
session.add(DbRunState(id=1, group_id=1, value=state.model_dump(mode="json"))) | ||
session.flush() | ||
session.add(DbPrIdToAutofixRunIdMapping(provider="test", pr_id=1, run_id=1)) | ||
session.commit() | ||
|
||
retrieved_state = get_autofix_state_from_pr_id("test", 2) | ||
self.assertIsNone(retrieved_state) |