Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .egg/schemas/contract.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@
"circuit_breaker": {
"$ref": "#/$defs/circuitBreaker"
},
"workflow_owner": {
"type": ["string", "null"],
"description": "GitHub username of the user who initiated the SDLC workflow (added the egg-sdlc label)",
"default": null
},
"audit_log": {
"type": "array",
"description": "Audit trail of all modifications",
Expand Down
45 changes: 45 additions & 0 deletions .github/workflows/sdlc-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
branch_name: ${{ steps.setup.outputs.branch_name }}
current_phase: ${{ steps.setup.outputs.current_phase }}
contract_exists: ${{ steps.setup.outputs.contract_exists }}
workflow_owner: ${{ steps.setup.outputs.workflow_owner }}

steps:
- name: Generate bot token
Expand Down Expand Up @@ -87,6 +88,7 @@ jobs:
DISPATCH_ISSUE: ${{ github.event.inputs.issue_number }}
LABELED_ISSUE: ${{ github.event.issue.number }}
STARTING_PHASE: ${{ github.event.inputs.starting_phase || 'refine' }}
EVENT_SENDER: ${{ github.event.sender.login }}
run: |
set -euo pipefail

Expand All @@ -112,6 +114,19 @@ jobs:

echo "issue_title=${ISSUE_TITLE}" >> "$GITHUB_OUTPUT"

# Capture workflow owner (the user who triggered the workflow)
# This is the user who added the egg-sdlc label or dispatched the workflow
WORKFLOW_OWNER="${EVENT_SENDER:-}"

# Validate workflow owner format (defense-in-depth)
# GitHub usernames are alphanumeric with hyphens only
if [[ -n "$WORKFLOW_OWNER" ]] && ! [[ "$WORKFLOW_OWNER" =~ ^[a-zA-Z0-9-]+$ ]]; then
echo "::warning::Invalid workflow owner format, skipping: ${WORKFLOW_OWNER}"
WORKFLOW_OWNER=""
fi

echo "workflow_owner=${WORKFLOW_OWNER}" >> "$GITHUB_OUTPUT"

# Branch name for this issue
BRANCH_NAME="egg/issue-${ISSUE_NUMBER}"
echo "branch_name=${BRANCH_NAME}" >> "$GITHUB_OUTPUT"
Expand Down Expand Up @@ -140,6 +155,13 @@ jobs:
echo "current_phase=${STARTING_PHASE}" >> "$GITHUB_OUTPUT"

# Create initial contract
# Build workflow_owner value (null if empty, quoted string otherwise)
if [[ -n "$WORKFLOW_OWNER" ]]; then
WORKFLOW_OWNER_JSON="\"${WORKFLOW_OWNER}\""
else
WORKFLOW_OWNER_JSON="null"
fi

cat > "$CONTRACT_PATH" << EOF
{
"schemaVersion": "1.0",
Expand All @@ -157,6 +179,7 @@ jobs:
"max_total_cycles": 10,
"status": "closed"
},
"workflow_owner": ${WORKFLOW_OWNER_JSON},
"audit_log": []
}
EOF
Expand Down Expand Up @@ -643,6 +666,7 @@ jobs:
ISSUE_TITLE: ${{ needs.init.outputs.issue_title }}
BRANCH_NAME: ${{ needs.init.outputs.branch_name }}
PR_NUMBER: ${{ needs.implement.outputs.pr_number }}
WORKFLOW_OWNER: ${{ needs.init.outputs.workflow_owner }}

steps:
- name: Generate bot token
Expand Down Expand Up @@ -684,6 +708,12 @@ jobs:
FINAL_BODY="${EXISTING_BODY}"
FINAL_BODY="${FINAL_BODY}"$'\n\n'"---"
FINAL_BODY="${FINAL_BODY}"$'\n\n'"✅ All automated checks passed. Ready for human review."

# Add reviewer assignment note if workflow owner is available
if [[ -n "${WORKFLOW_OWNER}" ]]; then
FINAL_BODY="${FINAL_BODY}"$'\n\n'"Reviewer: @${WORKFLOW_OWNER}"
fi

FINAL_BODY="${FINAL_BODY}"$'\n\n'"Authored-by: egg"

gh pr edit "${PR_NUMBER}" --body "$FINAL_BODY"
Expand All @@ -693,6 +723,21 @@ jobs:

echo "PR #${PR_NUMBER} marked ready for human review"

- name: Add workflow owner as reviewer
if: env.WORKFLOW_OWNER != ''
env:
GH_TOKEN: ${{ steps.bot-token.outputs.token }}
run: |
set -euo pipefail

# Add the workflow owner as a PR reviewer
# This may warn if the user doesn't have permission but won't fail
if gh pr edit "${PR_NUMBER}" --add-reviewer "${WORKFLOW_OWNER}"; then
echo "Added @${WORKFLOW_OWNER} as reviewer for PR #${PR_NUMBER}"
else
echo "::warning::Could not add @${WORKFLOW_OWNER} as reviewer (they may not have permission)"
fi

- name: Update contract phase
env:
GH_TOKEN: ${{ steps.bot-token.outputs.token }}
Expand Down
4 changes: 4 additions & 0 deletions shared/egg_contracts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ class Contract(BaseModel):
circuit_breaker: CircuitBreaker = Field(
default_factory=CircuitBreaker, description="Circuit breaker state"
)
workflow_owner: str | None = Field(
default=None,
description="GitHub username of the user who initiated the SDLC workflow",
)
audit_log: list[AuditEntry] = Field(default_factory=list, description="Audit trail")

def get_task(self, phase_id: str, task_id: str) -> Task | None:
Expand Down
63 changes: 63 additions & 0 deletions tests/shared/egg_contracts/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,31 @@ def test_minimal_contract(self):
assert contract.current_phase == PipelinePhase.REFINE
assert contract.phases == []
assert contract.decisions == []
assert contract.workflow_owner is None

def test_contract_with_workflow_owner(self):
"""Test creating a contract with workflow_owner field."""
contract = Contract(
issue=IssueInfo(
number=133,
title="Test issue",
url="https://github.com/owner/repo/issues/133",
),
workflow_owner="jwbron",
)
assert contract.workflow_owner == "jwbron"

def test_contract_workflow_owner_null(self):
"""Test that workflow_owner can be explicitly set to None."""
contract = Contract(
issue=IssueInfo(
number=133,
title="Test issue",
url="https://github.com/owner/repo/issues/133",
),
workflow_owner=None,
)
assert contract.workflow_owner is None

def test_full_contract(self):
"""Test creating a contract with all fields."""
Expand Down Expand Up @@ -339,3 +364,41 @@ def test_json_roundtrip(self):
assert restored.issue.number == original.issue.number
assert len(restored.phases) == 1
assert restored.phases[0].tasks[0].id == "task-1"

def test_json_roundtrip_with_workflow_owner(self):
"""Test that workflow_owner serializes and deserializes correctly."""
original = Contract(
issue=IssueInfo(
number=133,
title="Test",
url="https://example.com",
),
workflow_owner="testuser",
)

# Serialize
data = original.model_dump(mode="json")
assert data["workflow_owner"] == "testuser"

# Deserialize
restored = Contract.model_validate(data)
assert restored.workflow_owner == "testuser"

def test_json_roundtrip_with_null_workflow_owner(self):
"""Test that null workflow_owner serializes correctly."""
original = Contract(
issue=IssueInfo(
number=133,
title="Test",
url="https://example.com",
),
workflow_owner=None,
)

# Serialize
data = original.model_dump(mode="json")
assert data["workflow_owner"] is None

# Deserialize
restored = Contract.model_validate(data)
assert restored.workflow_owner is None
Loading