chore(client): refactoring
This commit is contained in:
parent
d18a812ea4
commit
1c70b5d949
5 changed files with 29 additions and 29 deletions
|
@ -7,7 +7,7 @@ import (
|
||||||
"path"
|
"path"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Team struct {
|
type OrganizationTeam struct {
|
||||||
CanCreateOrgRepo bool `json:"can_create_org_repo"`
|
CanCreateOrgRepo bool `json:"can_create_org_repo"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
|
@ -19,8 +19,8 @@ type Team struct {
|
||||||
UnitsMap map[string]string `json:"units_map"`
|
UnitsMap map[string]string `json:"units_map"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) TeamsList(ctx context.Context, organizationName string) ([]Team, error) {
|
func (c *Client) OrganizationTeamsList(ctx context.Context, organizationName string) ([]OrganizationTeam, error) {
|
||||||
var response []Team
|
var response []OrganizationTeam
|
||||||
uriRef := url.URL{Path: path.Join("api/v1/orgs", organizationName, "teams")}
|
uriRef := url.URL{Path: path.Join("api/v1/orgs", organizationName, "teams")}
|
||||||
if err := c.sendPaginated(ctx, "GET", &uriRef, nil, &response); err != nil {
|
if err := c.sendPaginated(ctx, "GET", &uriRef, nil, &response); err != nil {
|
||||||
return nil, fmt.Errorf("failed to list teams of organization %s: %w", organizationName, err)
|
return nil, fmt.Errorf("failed to list teams of organization %s: %w", organizationName, err)
|
|
@ -31,7 +31,7 @@ type RepositoryTransfer struct {
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Doer *User `json:"doer"`
|
Doer *User `json:"doer"`
|
||||||
Recipient *User `json:"recipient"`
|
Recipient *User `json:"recipient"`
|
||||||
Teams []Team `json:"teams"`
|
Teams []OrganizationTeam `json:"teams"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Repository struct {
|
type Repository struct {
|
||||||
|
|
|
@ -8,36 +8,36 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Secret struct {
|
type RepositoryActionsSecret struct {
|
||||||
CreatedAt time.Time `json:"created_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) RepoActionSecretDelete(ctx context.Context, owner string, repo string, name string) error {
|
func (c *Client) RepositoryActionsSecretCreateOrUpdate(ctx context.Context, owner string, repo string, name string, data string) error {
|
||||||
uriRef := url.URL{Path: path.Join("api/v1/repos", owner, repo, "actions/secrets", name)}
|
|
||||||
if _, err := c.send(ctx, "DELETE", &uriRef, nil, nil); err != nil {
|
|
||||||
return fmt.Errorf("failed to delete repository secret: %w", err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) RepoActionSecretPut(ctx context.Context, owner string, repo string, name string, data string) error {
|
|
||||||
uriRef := url.URL{Path: path.Join("api/v1/repos", owner, repo, "actions/secrets", name)}
|
uriRef := url.URL{Path: path.Join("api/v1/repos", owner, repo, "actions/secrets", name)}
|
||||||
type Payload struct {
|
type Payload struct {
|
||||||
Data string `json:"data"`
|
Data string `json:"data"`
|
||||||
}
|
}
|
||||||
payload := Payload{Data: data}
|
payload := Payload{Data: data}
|
||||||
if _, err := c.send(ctx, "PUT", &uriRef, &payload, nil); err != nil {
|
if _, err := c.send(ctx, "PUT", &uriRef, &payload, nil); err != nil {
|
||||||
return fmt.Errorf("failed to put repository secret: %w", err)
|
return fmt.Errorf("failed to create or update repository actions secret: %w", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) RepoActionSecretsList(ctx context.Context, owner string, repo string) ([]Secret, error) {
|
func (c *Client) RepositoryActionsSecretDelete(ctx context.Context, owner string, repo string, name string) error {
|
||||||
|
uriRef := url.URL{Path: path.Join("api/v1/repos", owner, repo, "actions/secrets", name)}
|
||||||
|
if _, err := c.send(ctx, "DELETE", &uriRef, nil, nil); err != nil {
|
||||||
|
return fmt.Errorf("failed to delete repository actions secret: %w", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) RepositoryActionsSecretsList(ctx context.Context, owner string, repo string) ([]RepositoryActionsSecret, error) {
|
||||||
uriRef := url.URL{Path: path.Join("api/v1/repos", owner, repo, "actions/secrets")}
|
uriRef := url.URL{Path: path.Join("api/v1/repos", owner, repo, "actions/secrets")}
|
||||||
var response []Secret
|
var response []RepositoryActionsSecret
|
||||||
if err := c.sendPaginated(ctx, "GET", &uriRef, nil, &response); err != nil {
|
if err := c.sendPaginated(ctx, "GET", &uriRef, nil, &response); err != nil {
|
||||||
return nil, fmt.Errorf("failed to list repository secrets: %w", err)
|
return nil, fmt.Errorf("failed to list repository actions secrets: %w", err)
|
||||||
}
|
}
|
||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
|
@ -84,14 +84,14 @@ func (d *RepositoryActionsSecretResource) Create(ctx context.Context, req resour
|
||||||
if resp.Diagnostics.HasError() {
|
if resp.Diagnostics.HasError() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err := d.client.RepoActionSecretPut(
|
err := d.client.RepositoryActionsSecretCreateOrUpdate(
|
||||||
ctx,
|
ctx,
|
||||||
data.Owner.ValueString(),
|
data.Owner.ValueString(),
|
||||||
data.Repository.ValueString(),
|
data.Repository.ValueString(),
|
||||||
data.Name.ValueString(),
|
data.Name.ValueString(),
|
||||||
data.Data.ValueString())
|
data.Data.ValueString())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resp.Diagnostics.AddError("CreateRepositoryActionsSecret", fmt.Sprintf("failed to put repository actions secret: %s", err))
|
resp.Diagnostics.AddError("CreateRepositoryActionsSecret", fmt.Sprintf("failed to create or update repository actions secret: %s", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
created, err := d.getRepositoryActionsSecret(ctx, data.Owner, data.Repository, data.Name)
|
created, err := d.getRepositoryActionsSecret(ctx, data.Owner, data.Repository, data.Name)
|
||||||
|
@ -109,7 +109,7 @@ func (d *RepositoryActionsSecretResource) Delete(ctx context.Context, req resour
|
||||||
if resp.Diagnostics.HasError() {
|
if resp.Diagnostics.HasError() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err := d.client.RepoActionSecretDelete(
|
err := d.client.RepositoryActionsSecretDelete(
|
||||||
ctx,
|
ctx,
|
||||||
data.Owner.ValueString(),
|
data.Owner.ValueString(),
|
||||||
data.Repository.ValueString(),
|
data.Repository.ValueString(),
|
||||||
|
@ -126,7 +126,7 @@ func (d *RepositoryActionsSecretResource) getRepositoryActionsSecret(
|
||||||
repository types.String,
|
repository types.String,
|
||||||
name types.String,
|
name types.String,
|
||||||
) (*timetypes.RFC3339, error) {
|
) (*timetypes.RFC3339, error) {
|
||||||
secrets, err := d.client.RepoActionSecretsList(
|
secrets, err := d.client.RepositoryActionsSecretsList(
|
||||||
ctx,
|
ctx,
|
||||||
owner.ValueString(),
|
owner.ValueString(),
|
||||||
repository.ValueString())
|
repository.ValueString())
|
||||||
|
@ -164,14 +164,14 @@ func (d *RepositoryActionsSecretResource) Update(ctx context.Context, req resour
|
||||||
if resp.Diagnostics.HasError() {
|
if resp.Diagnostics.HasError() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err := d.client.RepoActionSecretPut(
|
err := d.client.RepositoryActionsSecretCreateOrUpdate(
|
||||||
ctx,
|
ctx,
|
||||||
data.Owner.ValueString(),
|
data.Owner.ValueString(),
|
||||||
data.Repository.ValueString(),
|
data.Repository.ValueString(),
|
||||||
data.Name.ValueString(),
|
data.Name.ValueString(),
|
||||||
data.Data.ValueString())
|
data.Data.ValueString())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resp.Diagnostics.AddError("UpdateRepositoryActionsSecret", fmt.Sprintf("failed to put repository actions secret: %s", err))
|
resp.Diagnostics.AddError("UpdateRepositoryActionsSecret", fmt.Sprintf("failed to create or update repository actions secret: %s", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
created, err := d.getRepositoryActionsSecret(ctx, data.Owner, data.Repository, data.Name)
|
created, err := d.getRepositoryActionsSecret(ctx, data.Owner, data.Repository, data.Name)
|
||||||
|
|
|
@ -102,7 +102,7 @@ func (d *TeamsDataSource) Configure(ctx context.Context, req datasource.Configur
|
||||||
d.client, _ = req.ProviderData.(*client.Client)
|
d.client, _ = req.ProviderData.(*client.Client)
|
||||||
}
|
}
|
||||||
|
|
||||||
func populateTeamDataSourceModel(team *client.Team) *TeamDataSourceModel {
|
func populateTeamDataSourceModel(team *client.OrganizationTeam) *TeamDataSourceModel {
|
||||||
return &TeamDataSourceModel{
|
return &TeamDataSourceModel{
|
||||||
CanCreateOrgRepo: types.BoolValue(team.CanCreateOrgRepo),
|
CanCreateOrgRepo: types.BoolValue(team.CanCreateOrgRepo),
|
||||||
Description: types.StringValue(team.Description),
|
Description: types.StringValue(team.Description),
|
||||||
|
@ -121,7 +121,7 @@ func (d *TeamsDataSource) Read(ctx context.Context, req datasource.ReadRequest,
|
||||||
if resp.Diagnostics.HasError() {
|
if resp.Diagnostics.HasError() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
teams, err := d.client.TeamsList(ctx, data.OrganizationName.ValueString())
|
teams, err := d.client.OrganizationTeamsList(ctx, data.OrganizationName.ValueString())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resp.Diagnostics.AddError("ListTeams", fmt.Sprintf("failed to list teams: %s", err))
|
resp.Diagnostics.AddError("ListTeams", fmt.Sprintf("failed to list teams: %s", err))
|
||||||
return
|
return
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue