Skip to content

Commit

Permalink
feat(): add support for AWS codebuild PR
Browse files Browse the repository at this point in the history
  • Loading branch information
gkampitakis committed Nov 23, 2024
1 parent c5d6eb1 commit 19400e7
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Officially supported CI servers:
| Name | Constant | isPR |
| ------------------------------------------------------------------------------- | --------------------------- | ---- |
| [Agola CI](https://agola.io/) | `ci.AGOLA` ||
| [AWS CodeBuild](https://aws.amazon.com/codebuild/) | `ciinfo.CODEBUILD` | 🚫 |
| [AWS CodeBuild](https://aws.amazon.com/codebuild/) | `ciinfo.CODEBUILD` | |
| [AppVeyor](http://www.appveyor.com) | `ciinfo.APPVEYOR` ||
| [Azure Pipelines](https://azure.microsoft.com/en-us/services/devops/pipelines/) | `ciinfo.AZURE_PIPELINES` ||
| [Appcircle](https://appcircle.io/) | `ciinfo.APPCIRCLE` | 🚫 |
Expand Down
17 changes: 11 additions & 6 deletions ciinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,7 @@ func initialize() {
}

Name = vendor.name

for _, pr := range vendor.pr {
if IsPr = verifyPr(pr); IsPr {
break
}
}
IsPr = anyPr(vendor.pr)
}

IsCI = os.Getenv("CI") != "false" && (Name != "" || isCI())
Expand Down Expand Up @@ -107,6 +102,16 @@ func verifyCI(e env) bool {
return true
}

func anyPr(pr []pr) bool {
for _, p := range pr {
if verifyPr(p) {
return true
}
}

return false
}

func verifyPr(p pr) bool {
value, exists := os.LookupEnv(p.key)
if !exists {
Expand Down
48 changes: 48 additions & 0 deletions ciinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,54 @@ func TestCI(t *testing.T) {
})

for _, scenario := range []TestScenario{
{
description: "AWS CodeBuild - PR",
expected: ScenarioExpected{
isPR: true,
name: "AWS CodeBuild",
constant: "CODEBUILD",
},
setup: func(t *testing.T) {
t.Setenv("CODEBUILD_BUILD_ARN", "arn")
t.Setenv("CODEBUILD_WEBHOOK_EVENT", "PULL_REQUEST_CREATED")
},
},
{
description: "AWS CodeBuild - PR",
expected: ScenarioExpected{
isPR: true,
name: "AWS CodeBuild",
constant: "CODEBUILD",
},
setup: func(t *testing.T) {
t.Setenv("CODEBUILD_BUILD_ARN", "arn")
t.Setenv("CODEBUILD_WEBHOOK_EVENT", "PULL_REQUEST_UPDATED")
},
},
{
description: "AWS CodeBuild - PR",
expected: ScenarioExpected{
isPR: true,
name: "AWS CodeBuild",
constant: "CODEBUILD",
},
setup: func(t *testing.T) {
t.Setenv("CODEBUILD_BUILD_ARN", "arn")
t.Setenv("CODEBUILD_WEBHOOK_EVENT", "PULL_REQUEST_REOPENED")
},
},
{
description: "AWS CodeBuild - Not PR",
expected: ScenarioExpected{
isPR: false,
name: "AWS CodeBuild",
constant: "CODEBUILD",
},
setup: func(t *testing.T) {
t.Setenv("CODEBUILD_BUILD_ARN", "arn")
t.Setenv("CODEBUILD_WEBHOOK_EVENT", "some-event")
},
},
{
description: "AppVeyor - PR",
expected: ScenarioExpected{
Expand Down
5 changes: 5 additions & 0 deletions vendors.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ var vendors = []vendor{
name: "AWS CodeBuild",
constant: "CODEBUILD",
env: []env{{key: "CODEBUILD_BUILD_ARN"}},
pr: []pr{
{key: "CODEBUILD_WEBHOOK_EVENT", eq: "PULL_REQUEST_CREATED"},
{key: "CODEBUILD_WEBHOOK_EVENT", eq: "PULL_REQUEST_UPDATED"},
{key: "CODEBUILD_WEBHOOK_EVENT", eq: "PULL_REQUEST_REOPENED"},
},
},
{
name: "Azure Pipelines",
Expand Down

0 comments on commit 19400e7

Please sign in to comment.