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

feature/985 branch protection checks #1415

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d42729e
feat: add new schema for check block resource under required_status_c…
TheQueenIsDead Dec 7, 2022
234cc25
feat: iterate provided `check` blocks and build array of RequiredStat…
TheQueenIsDead Dec 7, 2022
b99d568
feat: set default app_id to -1
TheQueenIsDead Dec 7, 2022
f482da2
feat: implement checks flattening for required status checks
TheQueenIsDead Dec 7, 2022
1c32a52
Add resource github_app_installation_repositories (#1376)
david-bain Dec 5, 2022
e2dadad
feat: adds new branch protection options for last reviewer and lockin…
wwsean08 Dec 5, 2022
a6565a9
feat(github_release): adding github_release resource and tests (#1122)
trentmillar Dec 6, 2022
b55408c
🚧 Workflows have changed
nickfloyd Dec 8, 2022
8959009
Issue template tweak (#1422)
kfcampbell Dec 9, 2022
702835a
feat: allow branch protection check app_id to be null
TheQueenIsDead Dec 8, 2022
3032488
chore: change branch protection flatten function to use GetAppID sdk …
TheQueenIsDead Dec 8, 2022
1deac0d
feat: change branch protection v3 utils to flatten and expand context…
TheQueenIsDead Dec 11, 2022
cb9c464
feat: change checks from it's own resource to a list of strings
TheQueenIsDead Dec 12, 2022
f9afc36
Merge branch 'main' into feature/985-branch-protection-contexts
TheQueenIsDead Dec 12, 2022
36e85f5
chore: resolve incorrect merge of main
TheQueenIsDead Dec 12, 2022
47cb610
chore: update deprecation notice on contexts array
TheQueenIsDead Dec 12, 2022
0d42123
chore(docs): Update branch_protection_v3 docs to mention the new `che…
TheQueenIsDead Dec 12, 2022
422f731
fix: Initialise literal empty slice of RequiredStatusCheck to mitigat…
TheQueenIsDead Dec 12, 2022
6cea244
Merge remote-tracking branch 'origin/feature/985-branch-protection-co…
TheQueenIsDead Dec 12, 2022
a2f7f5d
Merge branch 'main' into feature/985-branch-protection-contexts
kfcampbell Dec 13, 2022
6600e7b
chore(lint): resolve gosimple S1082 violation (errors.New => fmt.Errorf)
TheQueenIsDead Dec 13, 2022
b6e5785
Merge remote-tracking branch 'origin/feature/985-branch-protection-co…
TheQueenIsDead Dec 13, 2022
bfe46cd
Merge branch 'main' into feature/985-branch-protection-contexts
kfcampbell Dec 13, 2022
451b3a2
Merge branch 'main' into feature/985-branch-protection-contexts
TheQueenIsDead Dec 15, 2022
65264b5
Merge branch 'main' into feature/985-branch-protection-contexts
kfcampbell Jan 3, 2023
31989d9
Merge branch 'main' into feature/985-branch-protection-contexts
kfcampbell Jan 4, 2023
cdf30eb
chore: remove unused code comment
TheQueenIsDead Jan 10, 2023
d4bcf23
Merge remote-tracking branch 'origin/feature/985-branch-protection-co…
TheQueenIsDead Jan 10, 2023
7ee2fec
Merge branch 'main' into feature/985-branch-protection-contexts
TheQueenIsDead Jan 10, 2023
9c5eb96
Merge branch 'main' into feature/985-branch-protection-contexts
kfcampbell Jan 11, 2023
c71d939
Merge branch 'integrations:main' into feature/985-branch-protection-c…
TheQueenIsDead Jan 16, 2023
bd524a7
Merge branch 'main' into feature/985-branch-protection-contexts
kfcampbell Jan 17, 2023
5cb8eec
Merge branch 'main' into feature/985-branch-protection-contexts
kfcampbell Jan 18, 2023
736c824
Merge branch 'main' into feature/985-branch-protection-contexts
TheQueenIsDead Jan 20, 2023
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
22 changes: 20 additions & 2 deletions github/resource_github_branch_protection_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,30 @@ func resourceGithubBranchProtectionV3() *schema.Resource {
Default: false,
},
"contexts": {
Type: schema.TypeSet,
Optional: true,
Type: schema.TypeSet,
Optional: true,
Deprecated: "GitHub is deprecating the use of `contexts`. Use `check` blocks instead.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"check": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"context": {
Type: schema.TypeString,
Required: true,
},
"app_id": {
Type: schema.TypeInt,
Optional: true,
Default: -1,
TheQueenIsDead marked this conversation as resolved.
Show resolved Hide resolved
},
},
},
},
},
},
},
Expand Down
37 changes: 37 additions & 0 deletions github/resource_github_branch_protection_v3_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,24 @@ func flattenAndSetRequiredStatusChecks(d *schema.ResourceData, protection *githu
contexts = append(contexts, c)
}

var checks []interface{}
for _, chk := range rsc.Checks {
chkMap := make(map[string]interface{})
chkMap["context"] = chk.Context
chkMap["app_id"] = func() int {
if chk.AppID != nil {
TheQueenIsDead marked this conversation as resolved.
Show resolved Hide resolved
return int(*chk.AppID)
}
return -1
}()
checks = append(checks, chkMap)
}

return d.Set("required_status_checks", []interface{}{
map[string]interface{}{
"strict": rsc.Strict,
"contexts": schema.NewSet(schema.HashString, contexts),
"check": checks,
},
})
}
Expand Down Expand Up @@ -193,6 +207,29 @@ func expandRequiredStatusChecks(d *schema.ResourceData) (*github.RequiredStatusC

contexts := expandNestedSet(m, "contexts")
rsc.Contexts = contexts

// Iterate and parse checks
checks := m["check"].([]interface{})
var rscChecks []*github.RequiredStatusCheck
for _, c := range checks {
chk := c.(map[string]interface{})

var cContext string
if cContext, ok = chk["context"].(string); !ok {
return nil, errors.New("could not parse 'context' for required_status_checks check")
}
var cAppId int
if cAppId, ok = chk["app_id"].(int); !ok {
log.Printf("[DEBUG] app_id value: %v", chk["app_id"].(int))
return nil, errors.New("could not parse 'app_id' for required_status_checks check")
}
rscAppId := int64(cAppId)
rscChecks = append(rscChecks, &github.RequiredStatusCheck{
Context: cContext,
AppID: &rscAppId,
})
}
rsc.Checks = rscChecks
}
return rsc, nil
}
Expand Down