feat(provider): add repositories data-source
This commit is contained in:
parent
2063f5ffef
commit
f04d7b341d
10 changed files with 1171 additions and 173 deletions
|
@ -8,5 +8,6 @@ All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
- Added provider configuration.
|
- Added provider configuration.
|
||||||
- Added organizations data-source.
|
- Added organizations data-source.
|
||||||
|
- Added repositories data-source.
|
||||||
- Added teams data-source.
|
- Added teams data-source.
|
||||||
- Added users data-source.
|
- Added users data-source.
|
||||||
|
|
247
docs/data-sources/repositories.md
Normal file
247
docs/data-sources/repositories.md
Normal file
|
@ -0,0 +1,247 @@
|
||||||
|
---
|
||||||
|
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
||||||
|
page_title: "forgejo_repositories Data Source - terraform-provider-forgejo"
|
||||||
|
subcategory: ""
|
||||||
|
description: |-
|
||||||
|
Use this data source to retrieve information about existing forgejo repositories.
|
||||||
|
---
|
||||||
|
|
||||||
|
# forgejo_repositories (Data Source)
|
||||||
|
|
||||||
|
Use this data source to retrieve information about existing forgejo repositories.
|
||||||
|
|
||||||
|
## Example Usage
|
||||||
|
|
||||||
|
```terraform
|
||||||
|
data "forgejo_repositories" "example" {}
|
||||||
|
```
|
||||||
|
|
||||||
|
<!-- schema generated by tfplugindocs -->
|
||||||
|
## Schema
|
||||||
|
|
||||||
|
### Read-Only
|
||||||
|
|
||||||
|
- `elements` (Attributes List) The list of repositories. (see [below for nested schema](#nestedatt--elements))
|
||||||
|
|
||||||
|
<a id="nestedatt--elements"></a>
|
||||||
|
### Nested Schema for `elements`
|
||||||
|
|
||||||
|
Read-Only:
|
||||||
|
|
||||||
|
- `allow_fast_forward_only_merge` (Boolean) Whether fast forward only merges are allowed or not.
|
||||||
|
- `allow_merge_commits` (Boolean) Whether merge commits are allowed or not.
|
||||||
|
- `allow_rebase` (Boolean) Whether updating a pull request branch by rebase is allowed or not.
|
||||||
|
- `allow_rebase_explicit` (Boolean) Whether rebase then merge commits are allowed or not.
|
||||||
|
- `allow_rebase_update` (Boolean) Whether rebase then fast forward merges are allowed or not.
|
||||||
|
- `allow_squash_merge` (Boolean) Whether squash merge commits are allowed on this repository or not.
|
||||||
|
- `archived` (Boolean) Whether the repository is archived or not.
|
||||||
|
- `archived_at` (String) The datetime at which the repository was archived.
|
||||||
|
- `avatar_url` (String) The URL of the avatar for the repository.
|
||||||
|
- `clone_url` (String) The URL to clone the repository.
|
||||||
|
- `created_at` (String) The datetime at which the repository was created.
|
||||||
|
- `default_allow_maintainer_edit` (Boolean) Whether maintainers have edit permissions by default or not.
|
||||||
|
- `default_branch` (String) The name of the default branch.
|
||||||
|
- `default_delete_branch_after_merge` (Boolean) Whether pull request branches are deleted by default after a merge or not.
|
||||||
|
- `default_merge_style` (String) Name of the default merge style.
|
||||||
|
- `default_update_style` (String) Name of the default update style.
|
||||||
|
- `description` (String) A description string.
|
||||||
|
- `empty` (Boolean) Whether the repository is empty or not.
|
||||||
|
- `external_tracker` (Attributes) (see [below for nested schema](#nestedatt--elements--external_tracker))
|
||||||
|
- `external_wiki` (Attributes) (see [below for nested schema](#nestedatt--elements--external_wiki))
|
||||||
|
- `fork` (Boolean) Whether the repository is a fork or not.
|
||||||
|
- `forks_count` (Number) The number of times the repository has been forked.
|
||||||
|
- `full_name` (String) The full name of the repository.
|
||||||
|
- `globally_editable_wiki` (Boolean) Whether anyone can edit the wiki or not.
|
||||||
|
- `has_actions` (Boolean) Whether the actions unit is enabled or not.
|
||||||
|
- `has_issues` (Boolean) Whether the issues unit is enabled or not.
|
||||||
|
- `has_packages` (Boolean) Whether the packages unit is enabled or not.
|
||||||
|
- `has_projects` (Boolean) Whether the projects unit is enabled or not.
|
||||||
|
- `has_pull_requests` (Boolean) Whether the pull requests unit is enabled or not.
|
||||||
|
- `has_releases` (Boolean) Whether the releases unit is enabled or not.
|
||||||
|
- `has_wiki` (Boolean) Whether the wiki unit is enabled or not.
|
||||||
|
- `html_url` (String) The HTTP URL of the repository.
|
||||||
|
- `id` (Number) The identifier of the repository.
|
||||||
|
- `ignore_whitespace_conflicts` (Boolean) Whether whitespaces are ignored when detecting pull request conflicts or not.
|
||||||
|
- `internal` (Boolean) Whether this is an internal repository or not.
|
||||||
|
- `internal_tracker` (Attributes) (see [below for nested schema](#nestedatt--elements--internal_tracker))
|
||||||
|
- `language` (String) The main programming language used in the repository.
|
||||||
|
- `languages_url` (String) The URL to the languages page.
|
||||||
|
- `link` (String) The link.
|
||||||
|
- `mirror` (Boolean) Whether the repository is a mirror or not.
|
||||||
|
- `mirror_interval` (String) The mirror time interval.
|
||||||
|
- `mirror_updated` (String) The datetime at which the mirror was last updated.
|
||||||
|
- `name` (String) The name of the repository.
|
||||||
|
- `object_format_name` (String) The name of the object format.
|
||||||
|
- `open_issues_count` (Number) The number of open issues.
|
||||||
|
- `open_pr_counter` (Number) The number of open pull requests.
|
||||||
|
- `original_url` (String) The original URL.
|
||||||
|
- `owner` (Attributes) (see [below for nested schema](#nestedatt--elements--owner))
|
||||||
|
- `permissions` (Attributes) (see [below for nested schema](#nestedatt--elements--permissions))
|
||||||
|
- `private` (Boolean) Whether the repository is private or not.
|
||||||
|
- `release_counter` (Number) The number of releases.
|
||||||
|
- `repo_transfer` (Attributes) (see [below for nested schema](#nestedatt--elements--repo_transfer))
|
||||||
|
- `size` (Number) The size of the repository in KiB.
|
||||||
|
- `ssh_url` (String) The SSH URL.
|
||||||
|
- `stars_count` (Number) The number of stars.
|
||||||
|
- `template` (Boolean) Whether the repository is a template or not.
|
||||||
|
- `topics` (List of String) The list of topics.
|
||||||
|
- `updated_at` (String) The datetime at which the repository was last updated.
|
||||||
|
- `url` (String) The API URL.
|
||||||
|
- `watchers_count` (Number) The number of watchers.
|
||||||
|
- `website` (String) The website URL.
|
||||||
|
- `wiki_branch` (String) The name of the default branch of the wiki.
|
||||||
|
|
||||||
|
<a id="nestedatt--elements--external_tracker"></a>
|
||||||
|
### Nested Schema for `elements.external_tracker`
|
||||||
|
|
||||||
|
Read-Only:
|
||||||
|
|
||||||
|
- `description` (String) A description string.
|
||||||
|
- `external_tracker_format` (String) External issue tracker URL Format. Use the placeholders {user}, {repo} and {index} for the username, repository name and issue index.
|
||||||
|
- `external_tracker_regexp_pattern` (String) Regular Expression Pattern. The first captured group will be used in place of {index}.
|
||||||
|
- `external_tracker_style` (String) External issue tracker Number Format.
|
||||||
|
- `external_tracker_url` (String) A URL.
|
||||||
|
|
||||||
|
|
||||||
|
<a id="nestedatt--elements--external_wiki"></a>
|
||||||
|
### Nested Schema for `elements.external_wiki`
|
||||||
|
|
||||||
|
Read-Only:
|
||||||
|
|
||||||
|
- `description` (String) A description string.
|
||||||
|
- `external_wiki_url` (String) A URL.
|
||||||
|
|
||||||
|
|
||||||
|
<a id="nestedatt--elements--internal_tracker"></a>
|
||||||
|
### Nested Schema for `elements.internal_tracker`
|
||||||
|
|
||||||
|
Read-Only:
|
||||||
|
|
||||||
|
- `allow_only_contributors_to_track_time` (Boolean) Whether only contributors are allowed to track time on issues or not.
|
||||||
|
- `enable_issue_dependencies` (Boolean) Whether issue dependencies are enabled or not.
|
||||||
|
- `enable_time_tracker` (Boolean) Whether time tracking is enabled or not.
|
||||||
|
|
||||||
|
|
||||||
|
<a id="nestedatt--elements--owner"></a>
|
||||||
|
### Nested Schema for `elements.owner`
|
||||||
|
|
||||||
|
Read-Only:
|
||||||
|
|
||||||
|
- `active` (Boolean) Whether the user is active or not.
|
||||||
|
- `avatar_url` (String) The user's avatar URL.
|
||||||
|
- `created` (String) The user's creation date and time.
|
||||||
|
- `description` (String) A description string.
|
||||||
|
- `email` (String) The user's email address.
|
||||||
|
- `followers_count` (Number) The number of followers.
|
||||||
|
- `following_count` (Number) The number of followings.
|
||||||
|
- `full_name` (String) The user's full name.
|
||||||
|
- `html_url` (String) The URL to this user's Forgejo profile page.
|
||||||
|
- `id` (Number) The identifier of the user.
|
||||||
|
- `is_admin` (Boolean) Whether the user is an admin or not.
|
||||||
|
- `language` (String) The user's chosen language.
|
||||||
|
- `last_login` (String) The user's last login date and time.
|
||||||
|
- `location` (String) The user's advertised location.
|
||||||
|
- `login` (String) The login of the user.
|
||||||
|
- `login_name` (String) The user's authentication sign-in name.
|
||||||
|
- `prohibit_login` (Boolean) Whether the user is allowed to log in or not.
|
||||||
|
- `pronouns` (String) The user's advertised pronouns.
|
||||||
|
- `restricted` (Boolean) Whether the user is restricted or not.
|
||||||
|
- `source_id` (Number) The identifier of the users authentication source.
|
||||||
|
- `starred_repos_count` (Number) The number of repositoties starred by the user.
|
||||||
|
- `visibility` (String) The user's visibility option: limited, private, public.
|
||||||
|
- `website` (String) The user's advertised website.
|
||||||
|
|
||||||
|
|
||||||
|
<a id="nestedatt--elements--permissions"></a>
|
||||||
|
### Nested Schema for `elements.permissions`
|
||||||
|
|
||||||
|
Read-Only:
|
||||||
|
|
||||||
|
- `admin` (Boolean) Admin permission.
|
||||||
|
- `pull` (Boolean) Pull permission.
|
||||||
|
- `push` (Boolean) Push permission.
|
||||||
|
|
||||||
|
|
||||||
|
<a id="nestedatt--elements--repo_transfer"></a>
|
||||||
|
### Nested Schema for `elements.repo_transfer`
|
||||||
|
|
||||||
|
Read-Only:
|
||||||
|
|
||||||
|
- `description` (String) A description string.
|
||||||
|
- `doer` (Attributes) (see [below for nested schema](#nestedatt--elements--repo_transfer--doer))
|
||||||
|
- `recipient` (Attributes) (see [below for nested schema](#nestedatt--elements--repo_transfer--recipient))
|
||||||
|
- `teams` (Attributes List) The list of teams for an organization. (see [below for nested schema](#nestedatt--elements--repo_transfer--teams))
|
||||||
|
|
||||||
|
<a id="nestedatt--elements--repo_transfer--doer"></a>
|
||||||
|
### Nested Schema for `elements.repo_transfer.doer`
|
||||||
|
|
||||||
|
Read-Only:
|
||||||
|
|
||||||
|
- `active` (Boolean) Whether the user is active or not.
|
||||||
|
- `avatar_url` (String) The user's avatar URL.
|
||||||
|
- `created` (String) The user's creation date and time.
|
||||||
|
- `description` (String) A description string.
|
||||||
|
- `email` (String) The user's email address.
|
||||||
|
- `followers_count` (Number) The number of followers.
|
||||||
|
- `following_count` (Number) The number of followings.
|
||||||
|
- `full_name` (String) The user's full name.
|
||||||
|
- `html_url` (String) The URL to this user's Forgejo profile page.
|
||||||
|
- `id` (Number) The identifier of the user.
|
||||||
|
- `is_admin` (Boolean) Whether the user is an admin or not.
|
||||||
|
- `language` (String) The user's chosen language.
|
||||||
|
- `last_login` (String) The user's last login date and time.
|
||||||
|
- `location` (String) The user's advertised location.
|
||||||
|
- `login` (String) The login of the user.
|
||||||
|
- `login_name` (String) The user's authentication sign-in name.
|
||||||
|
- `prohibit_login` (Boolean) Whether the user is allowed to log in or not.
|
||||||
|
- `pronouns` (String) The user's advertised pronouns.
|
||||||
|
- `restricted` (Boolean) Whether the user is restricted or not.
|
||||||
|
- `source_id` (Number) The identifier of the users authentication source.
|
||||||
|
- `starred_repos_count` (Number) The number of repositoties starred by the user.
|
||||||
|
- `visibility` (String) The user's visibility option: limited, private, public.
|
||||||
|
- `website` (String) The user's advertised website.
|
||||||
|
|
||||||
|
|
||||||
|
<a id="nestedatt--elements--repo_transfer--recipient"></a>
|
||||||
|
### Nested Schema for `elements.repo_transfer.recipient`
|
||||||
|
|
||||||
|
Read-Only:
|
||||||
|
|
||||||
|
- `active` (Boolean) Whether the user is active or not.
|
||||||
|
- `avatar_url` (String) The user's avatar URL.
|
||||||
|
- `created` (String) The user's creation date and time.
|
||||||
|
- `description` (String) A description string.
|
||||||
|
- `email` (String) The user's email address.
|
||||||
|
- `followers_count` (Number) The number of followers.
|
||||||
|
- `following_count` (Number) The number of followings.
|
||||||
|
- `full_name` (String) The user's full name.
|
||||||
|
- `html_url` (String) The URL to this user's Forgejo profile page.
|
||||||
|
- `id` (Number) The identifier of the user.
|
||||||
|
- `is_admin` (Boolean) Whether the user is an admin or not.
|
||||||
|
- `language` (String) The user's chosen language.
|
||||||
|
- `last_login` (String) The user's last login date and time.
|
||||||
|
- `location` (String) The user's advertised location.
|
||||||
|
- `login` (String) The login of the user.
|
||||||
|
- `login_name` (String) The user's authentication sign-in name.
|
||||||
|
- `prohibit_login` (Boolean) Whether the user is allowed to log in or not.
|
||||||
|
- `pronouns` (String) The user's advertised pronouns.
|
||||||
|
- `restricted` (Boolean) Whether the user is restricted or not.
|
||||||
|
- `source_id` (Number) The identifier of the users authentication source.
|
||||||
|
- `starred_repos_count` (Number) The number of repositoties starred by the user.
|
||||||
|
- `visibility` (String) The user's visibility option: limited, private, public.
|
||||||
|
- `website` (String) The user's advertised website.
|
||||||
|
|
||||||
|
|
||||||
|
<a id="nestedatt--elements--repo_transfer--teams"></a>
|
||||||
|
### Nested Schema for `elements.repo_transfer.teams`
|
||||||
|
|
||||||
|
Read-Only:
|
||||||
|
|
||||||
|
- `can_create_org_repo` (Boolean) Whether members of this team can create repositories that will belong to the organization.
|
||||||
|
- `description` (String) A description string.
|
||||||
|
- `id` (Number) The identifier of the team.
|
||||||
|
- `includes_all_repositories` (Boolean) Whether members of this team can access all the repositories that belong to the organization.
|
||||||
|
- `name` (String) The team's name are a part of.
|
||||||
|
- `permission` (String) The members' permission level on the organization.
|
||||||
|
- `units` (List of String) The list of units permissions.
|
||||||
|
- `units_map` (Map of String) The map of units permissions and their level.
|
|
@ -0,0 +1 @@
|
||||||
|
data "forgejo_repositories" "example" {}
|
7
internal/client/permissions.go
Normal file
7
internal/client/permissions.go
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
package client
|
||||||
|
|
||||||
|
type Permission struct {
|
||||||
|
Admin bool `json:"admin"`
|
||||||
|
Pull bool `json:"pull"`
|
||||||
|
Push bool `json:"push"`
|
||||||
|
}
|
122
internal/client/repositories.go
Normal file
122
internal/client/repositories.go
Normal file
|
@ -0,0 +1,122 @@
|
||||||
|
package client
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type RepositoryExternalTracker struct {
|
||||||
|
Description string `json:"description"`
|
||||||
|
Format string `json:"external_tracker_format"`
|
||||||
|
RegexpPattern string `json:"external_tracker_regexp_pattern"`
|
||||||
|
Style string `json:"external_tracker_style"`
|
||||||
|
Url string `json:"external_tracker_url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type RepositoryExternalWiki struct {
|
||||||
|
Description string `json:"description"`
|
||||||
|
Url string `json:"external_wiki_url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type RepositoryInternalTracker struct {
|
||||||
|
AllowOnlyContributorsToTrackTime bool `json:"allow_only_contributors_to_track_time"`
|
||||||
|
EnableIssueDependencies bool `json:"enable_issue_dependencies"`
|
||||||
|
EnableTimeTracker bool `json:"enable_time_tracker"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type RepositoryTransfer struct {
|
||||||
|
Description string `json:"description"`
|
||||||
|
Doer *User `json:"doer"`
|
||||||
|
Recipient *User `json:"recipient"`
|
||||||
|
Teams []Team `json:"teams"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Repository struct {
|
||||||
|
AllowFastForwardOnlyMerge bool `json:"allow_fast_forward_only_merge"`
|
||||||
|
AllowMergeCommits bool `json:"allow_merge_commits"`
|
||||||
|
AllowRebase bool `json:"allow_rebase"`
|
||||||
|
AllowRebaseExplicit bool `json:"allow_rebase_explicit"`
|
||||||
|
AllowRebaseUpdate bool `json:"allow_rebase_update"`
|
||||||
|
AllowSquashMerge bool `json:"allow_squash_merge"`
|
||||||
|
ArchivedAt time.Time `json:"archived_at"`
|
||||||
|
Archived bool `json:"archived"`
|
||||||
|
AvatarUrl string `json:"avatar_url"`
|
||||||
|
CloneUrl string `json:"clone_url"`
|
||||||
|
CreatedAt time.Time `json:"created_at"`
|
||||||
|
DefaultAllowMaintainerEdit bool `json:"default_allow_maintainer_edit"`
|
||||||
|
DefaultBranch string `json:"default_branch"`
|
||||||
|
DefaultDeleteBranchAfterMerge bool `json:"default_delete_branch_after_merge"`
|
||||||
|
DefaultMergeStyle string `json:"default_merge_style"`
|
||||||
|
DefaultUpdateStyle string `json:"default_update_style"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
Empty bool `json:"empty"`
|
||||||
|
ExternalTracker *RepositoryExternalTracker `json:"external_tracker"`
|
||||||
|
ExternalWiki *RepositoryExternalWiki `json:"external_wiki"`
|
||||||
|
Fork bool `json:"fork"`
|
||||||
|
ForksCount int64 `json:"forks_count"`
|
||||||
|
FullName string `json:"full_name"`
|
||||||
|
GloballyEditableWiki bool `json:"globally_editable_wiki"`
|
||||||
|
HasActions bool `json:"has_actions"`
|
||||||
|
HasIssues bool `json:"has_issues"`
|
||||||
|
HasPackages bool `json:"has_packages"`
|
||||||
|
HasProjects bool `json:"has_projects"`
|
||||||
|
HasPullRequests bool `json:"has_pull_requests"`
|
||||||
|
HasReleases bool `json:"has_releases"`
|
||||||
|
HasWiki bool `json:"has_wiki"`
|
||||||
|
HtmlUrl string `json:"html_url"`
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
IgnoreWhitespaceConflicts bool `json:"ignore_whitespace_conflicts"`
|
||||||
|
Internal bool `json:"internal"`
|
||||||
|
InternalTracker *RepositoryInternalTracker `json:"internal_tracker"`
|
||||||
|
Language string `json:"language"`
|
||||||
|
LanguagesUrl string `json:"languages_url"`
|
||||||
|
Link string `json:"link"`
|
||||||
|
Mirror bool `json:"mirror"`
|
||||||
|
MirrorInterval string `json:"mirror_interval"`
|
||||||
|
MirrorUpdated time.Time `json:"mirror_updated"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
ObjectFormatName string `json:"object_format_name"`
|
||||||
|
OpenIssuesCount int64 `json:"open_issues_count"`
|
||||||
|
OpenPrCounter int64 `json:"open_pr_counter"`
|
||||||
|
OriginalUrl string `json:"original_url"`
|
||||||
|
Owner *User `json:"owner"`
|
||||||
|
Parent *Repository `json:"parent"`
|
||||||
|
Permissions *Permission `json:"permissions"`
|
||||||
|
Private bool `json:"private"`
|
||||||
|
ReleaseCounter int64 `json:"release_counter"`
|
||||||
|
RepoTransfer *RepositoryTransfer `json:"repo_transfer"`
|
||||||
|
Size int64 `json:"size"`
|
||||||
|
SshUrl string `json:"ssh_url"`
|
||||||
|
StarsCount int64 `json:"stars_count"`
|
||||||
|
Template bool `json:"template"`
|
||||||
|
Topics []string `json:"topics"`
|
||||||
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
|
Url string `json:"url"`
|
||||||
|
WatchersCount int64 `json:"watchers_count"`
|
||||||
|
Website string `json:"website"`
|
||||||
|
WikiBranch string `json:"wiki_branch"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) RepositoriesList(ctx context.Context) ([]Repository, error) {
|
||||||
|
type Response struct {
|
||||||
|
Data []Repository `json:"data"`
|
||||||
|
Ok bool `json:"ok"`
|
||||||
|
}
|
||||||
|
var response Response
|
||||||
|
query := make(url.Values)
|
||||||
|
query.Set("limit", "50")
|
||||||
|
query.Set("page", "1")
|
||||||
|
uriRef := url.URL{
|
||||||
|
Path: "api/v1/repos/search",
|
||||||
|
RawQuery: query.Encode(),
|
||||||
|
}
|
||||||
|
if err := c.Send(ctx, "GET", &uriRef, nil, &response); err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to search repositories: %w", err)
|
||||||
|
}
|
||||||
|
if !response.Ok {
|
||||||
|
return response.Data, fmt.Errorf("got a non OK status when querying repos/search")
|
||||||
|
}
|
||||||
|
return response.Data, nil
|
||||||
|
}
|
27
internal/provider/permissions.go
Normal file
27
internal/provider/permissions.go
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
package provider
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||||
|
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
type PermissionDataSourceModel struct {
|
||||||
|
Admin types.Bool `tfsdk:"admin"`
|
||||||
|
Pull types.Bool `tfsdk:"pull"`
|
||||||
|
Push types.Bool `tfsdk:"push"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var permissionSchemaAttributes = map[string]schema.Attribute{
|
||||||
|
"admin": schema.BoolAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "Admin permission.",
|
||||||
|
},
|
||||||
|
"pull": schema.BoolAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "Pull permission.",
|
||||||
|
},
|
||||||
|
"push": schema.BoolAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "Push permission.",
|
||||||
|
},
|
||||||
|
}
|
|
@ -81,6 +81,7 @@ func (p *Provider) Resources(ctx context.Context) []func() resource.Resource {
|
||||||
func (p *Provider) DataSources(ctx context.Context) []func() datasource.DataSource {
|
func (p *Provider) DataSources(ctx context.Context) []func() datasource.DataSource {
|
||||||
return []func() datasource.DataSource{
|
return []func() datasource.DataSource{
|
||||||
NewOrganizationsDataSource,
|
NewOrganizationsDataSource,
|
||||||
|
NewRepositoriesDataSource,
|
||||||
NewTeamsDataSource,
|
NewTeamsDataSource,
|
||||||
NewUsersDataSource,
|
NewUsersDataSource,
|
||||||
}
|
}
|
||||||
|
|
580
internal/provider/repositories_data_source.go
Normal file
580
internal/provider/repositories_data_source.go
Normal file
|
@ -0,0 +1,580 @@
|
||||||
|
package provider
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"git.adyxax.org/adyxax/terraform-provider-forgejo/internal/client"
|
||||||
|
"github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes"
|
||||||
|
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||||
|
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||||
|
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
type RepositoriesDataSource struct {
|
||||||
|
client *client.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ datasource.DataSource = &RepositoriesDataSource{} // Ensure provider defined types fully satisfy framework interfaces
|
||||||
|
func NewRepositoriesDataSource() datasource.DataSource {
|
||||||
|
return &RepositoriesDataSource{}
|
||||||
|
}
|
||||||
|
|
||||||
|
type RepositoriesDataSourceModel struct {
|
||||||
|
Elements []RepositoryDataSourceModel `tfsdk:"elements"`
|
||||||
|
}
|
||||||
|
type RepositoryDataSourceModel struct {
|
||||||
|
AllowFastForwardOnlyMerge types.Bool `tfsdk:"allow_fast_forward_only_merge"`
|
||||||
|
AllowMergeCommits types.Bool `tfsdk:"allow_merge_commits"`
|
||||||
|
AllowRebase types.Bool `tfsdk:"allow_rebase"`
|
||||||
|
AllowRebaseExplicit types.Bool `tfsdk:"allow_rebase_explicit"`
|
||||||
|
AllowRebaseUpdate types.Bool `tfsdk:"allow_rebase_update"`
|
||||||
|
AllowSquashMerge types.Bool `tfsdk:"allow_squash_merge"`
|
||||||
|
ArchivedAt timetypes.RFC3339 `tfsdk:"archived_at"`
|
||||||
|
Archived types.Bool `tfsdk:"archived"`
|
||||||
|
AvatarUrl types.String `tfsdk:"avatar_url"`
|
||||||
|
CloneUrl types.String `tfsdk:"clone_url"`
|
||||||
|
CreatedAt timetypes.RFC3339 `tfsdk:"created_at"`
|
||||||
|
DefaultAllowMaintainerEdit types.Bool `tfsdk:"default_allow_maintainer_edit"`
|
||||||
|
DefaultBranch types.String `tfsdk:"default_branch"`
|
||||||
|
DefaultDeleteBranchAfterMerge types.Bool `tfsdk:"default_delete_branch_after_merge"`
|
||||||
|
DefaultMergeStyle types.String `tfsdk:"default_merge_style"`
|
||||||
|
DefaultUpdateStyle types.String `tfsdk:"default_update_style"`
|
||||||
|
Description types.String `tfsdk:"description"`
|
||||||
|
Empty types.Bool `tfsdk:"empty"`
|
||||||
|
ExternalTracker *RepositoryExternalTrackerDataSourceModel `tfsdk:"external_tracker"`
|
||||||
|
ExternalWiki *RepositoryExternalWikiDataSourceModel `tfsdk:"external_wiki"`
|
||||||
|
Fork types.Bool `tfsdk:"fork"`
|
||||||
|
ForksCount types.Int64 `tfsdk:"forks_count"`
|
||||||
|
FullName types.String `tfsdk:"full_name"`
|
||||||
|
GloballyEditableWiki types.Bool `tfsdk:"globally_editable_wiki"`
|
||||||
|
HasActions types.Bool `tfsdk:"has_actions"`
|
||||||
|
HasIssues types.Bool `tfsdk:"has_issues"`
|
||||||
|
HasPackages types.Bool `tfsdk:"has_packages"`
|
||||||
|
HasProjects types.Bool `tfsdk:"has_projects"`
|
||||||
|
HasPullRequests types.Bool `tfsdk:"has_pull_requests"`
|
||||||
|
HasReleases types.Bool `tfsdk:"has_releases"`
|
||||||
|
HasWiki types.Bool `tfsdk:"has_wiki"`
|
||||||
|
HtmlUrl types.String `tfsdk:"html_url"`
|
||||||
|
Id types.Int64 `tfsdk:"id"`
|
||||||
|
IgnoreWhitespaceConflicts types.Bool `tfsdk:"ignore_whitespace_conflicts"`
|
||||||
|
Internal types.Bool `tfsdk:"internal"`
|
||||||
|
InternalTracker *RepositoryInternalTrackerDataSourceModel `tfsdk:"internal_tracker"`
|
||||||
|
Language types.String `tfsdk:"language"`
|
||||||
|
LanguagesUrl types.String `tfsdk:"languages_url"`
|
||||||
|
Link types.String `tfsdk:"link"`
|
||||||
|
Mirror types.Bool `tfsdk:"mirror"`
|
||||||
|
MirrorInterval types.String `tfsdk:"mirror_interval"`
|
||||||
|
MirrorUpdated timetypes.RFC3339 `tfsdk:"mirror_updated"`
|
||||||
|
Name types.String `tfsdk:"name"`
|
||||||
|
ObjectFormatName types.String `tfsdk:"object_format_name"`
|
||||||
|
OpenIssuesCount types.Int64 `tfsdk:"open_issues_count"`
|
||||||
|
OpenPrCounter types.Int64 `tfsdk:"open_pr_counter"`
|
||||||
|
OriginalUrl types.String `tfsdk:"original_url"`
|
||||||
|
Owner *UserDataSourceModel `tfsdk:"owner"`
|
||||||
|
//terraform does not support recursive schema definitions
|
||||||
|
//Parent *RepositoryDataSourceModel `tfsdk:"parent"`
|
||||||
|
Permissions *PermissionDataSourceModel `tfsdk:"permissions"`
|
||||||
|
Private types.Bool `tfsdk:"private"`
|
||||||
|
ReleaseCounter types.Int64 `tfsdk:"release_counter"`
|
||||||
|
RepoTransfer *RepositoryTransferDataSourceModel `tfsdk:"repo_transfer"`
|
||||||
|
Size types.Int64 `tfsdk:"size"`
|
||||||
|
SshUrl types.String `tfsdk:"ssh_url"`
|
||||||
|
StarsCount types.Int64 `tfsdk:"stars_count"`
|
||||||
|
Template types.Bool `tfsdk:"template"`
|
||||||
|
Topics []types.String `tfsdk:"topics"`
|
||||||
|
UpdatedAt timetypes.RFC3339 `tfsdk:"updated_at"`
|
||||||
|
Url types.String `tfsdk:"url"`
|
||||||
|
WatchersCount types.Int64 `tfsdk:"watchers_count"`
|
||||||
|
Website types.String `tfsdk:"website"`
|
||||||
|
WikiBranch types.String `tfsdk:"wiki_branch"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type RepositoryExternalTrackerDataSourceModel struct {
|
||||||
|
Description types.String `tfsdk:"description"`
|
||||||
|
Format types.String `tfsdk:"external_tracker_format"`
|
||||||
|
RegexpPattern types.String `tfsdk:"external_tracker_regexp_pattern"`
|
||||||
|
Style types.String `tfsdk:"external_tracker_style"`
|
||||||
|
Url types.String `tfsdk:"external_tracker_url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type RepositoryExternalWikiDataSourceModel struct {
|
||||||
|
Description types.String `tfsdk:"description"`
|
||||||
|
Url types.String `tfsdk:"external_wiki_url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type RepositoryInternalTrackerDataSourceModel struct {
|
||||||
|
AllowOnlyContributorsToTrackTime types.Bool `tfsdk:"allow_only_contributors_to_track_time"`
|
||||||
|
EnableIssueDependencies types.Bool `tfsdk:"enable_issue_dependencies"`
|
||||||
|
EnableTimeTracker types.Bool `tfsdk:"enable_time_tracker"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type RepositoryTransferDataSourceModel struct {
|
||||||
|
Description types.String `tfsdk:"description"`
|
||||||
|
Doer *UserDataSourceModel `tfsdk:"doer"`
|
||||||
|
Recipient *UserDataSourceModel `tfsdk:"recipient"`
|
||||||
|
Teams []TeamDataSourceModel `tfsdk:"teams"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *RepositoriesDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||||
|
resp.TypeName = req.ProviderTypeName + "_repositories"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *RepositoriesDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||||
|
resp.Schema = schema.Schema{
|
||||||
|
Attributes: map[string]schema.Attribute{
|
||||||
|
"elements": schema.ListNestedAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "The list of repositories.",
|
||||||
|
NestedObject: schema.NestedAttributeObject{
|
||||||
|
Attributes: map[string]schema.Attribute{
|
||||||
|
"allow_fast_forward_only_merge": schema.BoolAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "Whether fast forward only merges are allowed or not.",
|
||||||
|
},
|
||||||
|
"allow_merge_commits": schema.BoolAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "Whether merge commits are allowed or not.",
|
||||||
|
},
|
||||||
|
"allow_rebase": schema.BoolAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "Whether updating a pull request branch by rebase is allowed or not.",
|
||||||
|
},
|
||||||
|
"allow_rebase_explicit": schema.BoolAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "Whether rebase then merge commits are allowed or not.",
|
||||||
|
},
|
||||||
|
"allow_rebase_update": schema.BoolAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "Whether rebase then fast forward merges are allowed or not.",
|
||||||
|
},
|
||||||
|
"allow_squash_merge": schema.BoolAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "Whether squash merge commits are allowed on this repository or not.",
|
||||||
|
},
|
||||||
|
"archived_at": schema.StringAttribute{
|
||||||
|
Computed: true,
|
||||||
|
CustomType: timetypes.RFC3339Type{},
|
||||||
|
MarkdownDescription: "The datetime at which the repository was archived.",
|
||||||
|
},
|
||||||
|
"archived": schema.BoolAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "Whether the repository is archived or not.",
|
||||||
|
},
|
||||||
|
"avatar_url": schema.StringAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "The URL of the avatar for the repository.",
|
||||||
|
},
|
||||||
|
"clone_url": schema.StringAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "The URL to clone the repository.",
|
||||||
|
},
|
||||||
|
"created_at": schema.StringAttribute{
|
||||||
|
Computed: true,
|
||||||
|
CustomType: timetypes.RFC3339Type{},
|
||||||
|
MarkdownDescription: "The datetime at which the repository was created.",
|
||||||
|
},
|
||||||
|
"default_allow_maintainer_edit": schema.BoolAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "Whether maintainers have edit permissions by default or not.",
|
||||||
|
},
|
||||||
|
"default_branch": schema.StringAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "The name of the default branch.",
|
||||||
|
},
|
||||||
|
"default_delete_branch_after_merge": schema.BoolAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "Whether pull request branches are deleted by default after a merge or not.",
|
||||||
|
},
|
||||||
|
"default_merge_style": schema.StringAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "Name of the default merge style.",
|
||||||
|
},
|
||||||
|
"default_update_style": schema.StringAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "Name of the default update style.",
|
||||||
|
},
|
||||||
|
"description": schema.StringAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "A description string.",
|
||||||
|
},
|
||||||
|
"empty": schema.BoolAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "Whether the repository is empty or not.",
|
||||||
|
},
|
||||||
|
"external_tracker": schema.SingleNestedAttribute{
|
||||||
|
Attributes: map[string]schema.Attribute{
|
||||||
|
"description": schema.StringAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "A description string.",
|
||||||
|
},
|
||||||
|
"external_tracker_format": schema.StringAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "External issue tracker URL Format. Use the placeholders {user}, {repo} and {index} for the username, repository name and issue index.",
|
||||||
|
},
|
||||||
|
"external_tracker_regexp_pattern": schema.StringAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "Regular Expression Pattern. The first captured group will be used in place of {index}.",
|
||||||
|
},
|
||||||
|
"external_tracker_style": schema.StringAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "External issue tracker Number Format.",
|
||||||
|
},
|
||||||
|
"external_tracker_url": schema.StringAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "A URL.",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"external_wiki": schema.SingleNestedAttribute{
|
||||||
|
Attributes: map[string]schema.Attribute{
|
||||||
|
"description": schema.StringAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "A description string.",
|
||||||
|
},
|
||||||
|
"external_wiki_url": schema.StringAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "A URL.",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"fork": schema.BoolAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "Whether the repository is a fork or not.",
|
||||||
|
},
|
||||||
|
"forks_count": schema.Int64Attribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "The number of times the repository has been forked.",
|
||||||
|
},
|
||||||
|
"full_name": schema.StringAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "The full name of the repository.",
|
||||||
|
},
|
||||||
|
"globally_editable_wiki": schema.BoolAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "Whether anyone can edit the wiki or not.",
|
||||||
|
},
|
||||||
|
"has_actions": schema.BoolAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "Whether the actions unit is enabled or not.",
|
||||||
|
},
|
||||||
|
"has_issues": schema.BoolAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "Whether the issues unit is enabled or not.",
|
||||||
|
},
|
||||||
|
"has_packages": schema.BoolAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "Whether the packages unit is enabled or not.",
|
||||||
|
},
|
||||||
|
"has_projects": schema.BoolAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "Whether the projects unit is enabled or not.",
|
||||||
|
},
|
||||||
|
"has_pull_requests": schema.BoolAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "Whether the pull requests unit is enabled or not.",
|
||||||
|
},
|
||||||
|
"has_releases": schema.BoolAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "Whether the releases unit is enabled or not.",
|
||||||
|
},
|
||||||
|
"has_wiki": schema.BoolAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "Whether the wiki unit is enabled or not.",
|
||||||
|
},
|
||||||
|
"html_url": schema.StringAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "The HTTP URL of the repository.",
|
||||||
|
},
|
||||||
|
"id": schema.Int64Attribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "The identifier of the repository.",
|
||||||
|
},
|
||||||
|
"ignore_whitespace_conflicts": schema.BoolAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "Whether whitespaces are ignored when detecting pull request conflicts or not.",
|
||||||
|
},
|
||||||
|
"internal": schema.BoolAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "Whether this is an internal repository or not.",
|
||||||
|
},
|
||||||
|
"internal_tracker": schema.SingleNestedAttribute{
|
||||||
|
Attributes: map[string]schema.Attribute{
|
||||||
|
"allow_only_contributors_to_track_time": schema.BoolAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "Whether only contributors are allowed to track time on issues or not.",
|
||||||
|
},
|
||||||
|
"enable_issue_dependencies": schema.BoolAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "Whether issue dependencies are enabled or not.",
|
||||||
|
},
|
||||||
|
"enable_time_tracker": schema.BoolAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "Whether time tracking is enabled or not.",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"language": schema.StringAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "The main programming language used in the repository.",
|
||||||
|
},
|
||||||
|
"languages_url": schema.StringAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "The URL to the languages page.",
|
||||||
|
},
|
||||||
|
"link": schema.StringAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "The link.",
|
||||||
|
},
|
||||||
|
"mirror": schema.BoolAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "Whether the repository is a mirror or not.",
|
||||||
|
},
|
||||||
|
"mirror_interval": schema.StringAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "The mirror time interval.",
|
||||||
|
},
|
||||||
|
"mirror_updated": schema.StringAttribute{
|
||||||
|
Computed: true,
|
||||||
|
CustomType: timetypes.RFC3339Type{},
|
||||||
|
MarkdownDescription: "The datetime at which the mirror was last updated.",
|
||||||
|
},
|
||||||
|
"name": schema.StringAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "The name of the repository.",
|
||||||
|
},
|
||||||
|
"object_format_name": schema.StringAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "The name of the object format.",
|
||||||
|
},
|
||||||
|
"open_issues_count": schema.Int64Attribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "The number of open issues.",
|
||||||
|
},
|
||||||
|
"open_pr_counter": schema.Int64Attribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "The number of open pull requests.",
|
||||||
|
},
|
||||||
|
"original_url": schema.StringAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "The original URL.",
|
||||||
|
},
|
||||||
|
"owner": schema.SingleNestedAttribute{
|
||||||
|
Attributes: userSchemaAttributes,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
//"parent"
|
||||||
|
"permissions": schema.SingleNestedAttribute{
|
||||||
|
Attributes: permissionSchemaAttributes,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"private": schema.BoolAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "Whether the repository is private or not.",
|
||||||
|
},
|
||||||
|
"release_counter": schema.Int64Attribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "The number of releases.",
|
||||||
|
},
|
||||||
|
"repo_transfer": schema.SingleNestedAttribute{
|
||||||
|
Attributes: map[string]schema.Attribute{
|
||||||
|
"description": schema.StringAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "A description string.",
|
||||||
|
},
|
||||||
|
"doer": schema.SingleNestedAttribute{
|
||||||
|
Attributes: userSchemaAttributes,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"recipient": schema.SingleNestedAttribute{
|
||||||
|
Attributes: userSchemaAttributes,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"teams": teamSchemaAttributes,
|
||||||
|
},
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"size": schema.Int64Attribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "The size of the repository in KiB.",
|
||||||
|
},
|
||||||
|
"ssh_url": schema.StringAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "The SSH URL.",
|
||||||
|
},
|
||||||
|
"stars_count": schema.Int64Attribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "The number of stars.",
|
||||||
|
},
|
||||||
|
"template": schema.BoolAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "Whether the repository is a template or not.",
|
||||||
|
},
|
||||||
|
"topics": schema.ListAttribute{
|
||||||
|
Computed: true,
|
||||||
|
ElementType: types.StringType,
|
||||||
|
MarkdownDescription: "The list of topics.",
|
||||||
|
},
|
||||||
|
"updated_at": schema.StringAttribute{
|
||||||
|
Computed: true,
|
||||||
|
CustomType: timetypes.RFC3339Type{},
|
||||||
|
MarkdownDescription: "The datetime at which the repository was last updated.",
|
||||||
|
},
|
||||||
|
"url": schema.StringAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "The API URL.",
|
||||||
|
},
|
||||||
|
"watchers_count": schema.Int64Attribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "The number of watchers.",
|
||||||
|
},
|
||||||
|
"website": schema.StringAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "The website URL.",
|
||||||
|
},
|
||||||
|
"wiki_branch": schema.StringAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "The name of the default branch of the wiki.",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
MarkdownDescription: "Use this data source to retrieve information about existing forgejo repositories.",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *RepositoriesDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
||||||
|
d.client, _ = req.ProviderData.(*client.Client)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *RepositoriesDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||||
|
var data RepositoriesDataSourceModel
|
||||||
|
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
|
||||||
|
if resp.Diagnostics.HasError() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
repositories, err := d.client.RepositoriesList(ctx)
|
||||||
|
if err != nil {
|
||||||
|
resp.Diagnostics.AddError("ListRepositories", fmt.Sprintf("failed to list repositories: %s", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
repositoriesList := make([]RepositoryDataSourceModel, len(repositories))
|
||||||
|
for i, repository := range repositories {
|
||||||
|
repositoriesList[i] = RepositoryDataSourceModel{
|
||||||
|
AllowFastForwardOnlyMerge: types.BoolValue(repository.AllowFastForwardOnlyMerge),
|
||||||
|
AllowMergeCommits: types.BoolValue(repository.AllowMergeCommits),
|
||||||
|
AllowRebase: types.BoolValue(repository.AllowRebase),
|
||||||
|
AllowRebaseExplicit: types.BoolValue(repository.AllowRebaseExplicit),
|
||||||
|
AllowRebaseUpdate: types.BoolValue(repository.AllowRebaseUpdate),
|
||||||
|
AllowSquashMerge: types.BoolValue(repository.AllowSquashMerge),
|
||||||
|
ArchivedAt: timetypes.NewRFC3339TimeValue(repository.ArchivedAt),
|
||||||
|
Archived: types.BoolValue(repository.Archived),
|
||||||
|
AvatarUrl: types.StringValue(repository.AvatarUrl),
|
||||||
|
CloneUrl: types.StringValue(repository.CloneUrl),
|
||||||
|
CreatedAt: timetypes.NewRFC3339TimeValue(repository.CreatedAt),
|
||||||
|
DefaultAllowMaintainerEdit: types.BoolValue(repository.DefaultAllowMaintainerEdit),
|
||||||
|
DefaultBranch: types.StringValue(repository.DefaultBranch),
|
||||||
|
DefaultDeleteBranchAfterMerge: types.BoolValue(repository.DefaultDeleteBranchAfterMerge),
|
||||||
|
DefaultMergeStyle: types.StringValue(repository.DefaultMergeStyle),
|
||||||
|
DefaultUpdateStyle: types.StringValue(repository.DefaultUpdateStyle),
|
||||||
|
Description: types.StringValue(repository.Description),
|
||||||
|
Empty: types.BoolValue(repository.Empty),
|
||||||
|
ExternalTracker: nil,
|
||||||
|
ExternalWiki: nil,
|
||||||
|
Fork: types.BoolValue(repository.Fork),
|
||||||
|
ForksCount: types.Int64Value(repository.ForksCount),
|
||||||
|
FullName: types.StringValue(repository.FullName),
|
||||||
|
GloballyEditableWiki: types.BoolValue(repository.GloballyEditableWiki),
|
||||||
|
HasActions: types.BoolValue(repository.HasActions),
|
||||||
|
HasIssues: types.BoolValue(repository.HasIssues),
|
||||||
|
HasPackages: types.BoolValue(repository.HasPackages),
|
||||||
|
HasProjects: types.BoolValue(repository.HasProjects),
|
||||||
|
HasPullRequests: types.BoolValue(repository.HasPullRequests),
|
||||||
|
HasReleases: types.BoolValue(repository.HasReleases),
|
||||||
|
HasWiki: types.BoolValue(repository.HasWiki),
|
||||||
|
HtmlUrl: types.StringValue(repository.HtmlUrl),
|
||||||
|
Id: types.Int64Value(repository.Id),
|
||||||
|
IgnoreWhitespaceConflicts: types.BoolValue(repository.IgnoreWhitespaceConflicts),
|
||||||
|
Internal: types.BoolValue(repository.Internal),
|
||||||
|
InternalTracker: nil,
|
||||||
|
Language: types.StringValue(repository.Language),
|
||||||
|
LanguagesUrl: types.StringValue(repository.LanguagesUrl),
|
||||||
|
Link: types.StringValue(repository.Link),
|
||||||
|
Mirror: types.BoolValue(repository.Mirror),
|
||||||
|
MirrorInterval: types.StringValue(repository.MirrorInterval),
|
||||||
|
MirrorUpdated: timetypes.NewRFC3339TimeValue(repository.MirrorUpdated),
|
||||||
|
Name: types.StringValue(repository.Name),
|
||||||
|
ObjectFormatName: types.StringValue(repository.ObjectFormatName),
|
||||||
|
OpenIssuesCount: types.Int64Value(repository.OpenIssuesCount),
|
||||||
|
OpenPrCounter: types.Int64Value(repository.OpenPrCounter),
|
||||||
|
OriginalUrl: types.StringValue(repository.OriginalUrl),
|
||||||
|
Owner: nil,
|
||||||
|
Permissions: nil,
|
||||||
|
Private: types.BoolValue(repository.Private),
|
||||||
|
ReleaseCounter: types.Int64Value(repository.ReleaseCounter),
|
||||||
|
RepoTransfer: nil,
|
||||||
|
Size: types.Int64Value(repository.Size),
|
||||||
|
SshUrl: types.StringValue(repository.SshUrl),
|
||||||
|
StarsCount: types.Int64Value(repository.StarsCount),
|
||||||
|
Template: types.BoolValue(repository.Template),
|
||||||
|
Topics: make([]types.String, len(repository.Topics)),
|
||||||
|
UpdatedAt: timetypes.NewRFC3339TimeValue(repository.UpdatedAt),
|
||||||
|
Url: types.StringValue(repository.Url),
|
||||||
|
WatchersCount: types.Int64Value(repository.WatchersCount),
|
||||||
|
Website: types.StringValue(repository.Website),
|
||||||
|
WikiBranch: types.StringValue(repository.WikiBranch),
|
||||||
|
}
|
||||||
|
if repository.ExternalTracker != nil {
|
||||||
|
repositoriesList[i].ExternalTracker = &RepositoryExternalTrackerDataSourceModel{
|
||||||
|
Description: types.StringValue(repository.ExternalTracker.Description),
|
||||||
|
Format: types.StringValue(repository.ExternalTracker.Format),
|
||||||
|
RegexpPattern: types.StringValue(repository.ExternalTracker.RegexpPattern),
|
||||||
|
Style: types.StringValue(repository.ExternalTracker.Style),
|
||||||
|
Url: types.StringValue(repository.ExternalTracker.Url),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if repository.ExternalWiki != nil {
|
||||||
|
repositoriesList[i].ExternalWiki = &RepositoryExternalWikiDataSourceModel{
|
||||||
|
Description: types.StringValue(repository.ExternalTracker.Description),
|
||||||
|
Url: types.StringValue(repository.ExternalTracker.Url),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if repository.InternalTracker != nil {
|
||||||
|
repositoriesList[i].InternalTracker = &RepositoryInternalTrackerDataSourceModel{
|
||||||
|
AllowOnlyContributorsToTrackTime: types.BoolValue(repository.InternalTracker.AllowOnlyContributorsToTrackTime),
|
||||||
|
EnableIssueDependencies: types.BoolValue(repository.InternalTracker.EnableIssueDependencies),
|
||||||
|
EnableTimeTracker: types.BoolValue(repository.InternalTracker.EnableTimeTracker),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if repository.Owner != nil {
|
||||||
|
repositoriesList[i].Owner = populateUserDataSourceModel(repository.Owner)
|
||||||
|
}
|
||||||
|
if repository.Permissions != nil {
|
||||||
|
repositoriesList[i].Permissions = &PermissionDataSourceModel{
|
||||||
|
Admin: types.BoolValue(repository.Permissions.Admin),
|
||||||
|
Pull: types.BoolValue(repository.Permissions.Pull),
|
||||||
|
Push: types.BoolValue(repository.Permissions.Push),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if repository.RepoTransfer != nil {
|
||||||
|
repositoriesList[i].RepoTransfer = &RepositoryTransferDataSourceModel{
|
||||||
|
Description: types.StringValue(repository.RepoTransfer.Description),
|
||||||
|
Doer: populateUserDataSourceModel(repository.RepoTransfer.Doer),
|
||||||
|
Recipient: populateUserDataSourceModel(repository.RepoTransfer.Recipient),
|
||||||
|
Teams: make([]TeamDataSourceModel, len(repository.RepoTransfer.Teams)),
|
||||||
|
}
|
||||||
|
for j, team := range repository.RepoTransfer.Teams {
|
||||||
|
repositoriesList[i].RepoTransfer.Teams[j] = *populateTeamDataSourceModel(&team)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for j, topic := range repository.Topics {
|
||||||
|
repositoriesList[i].Topics[j] = types.StringValue(topic)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data.Elements = repositoriesList
|
||||||
|
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
|
||||||
|
}
|
|
@ -42,10 +42,7 @@ func (d *TeamsDataSource) Metadata(ctx context.Context, req datasource.MetadataR
|
||||||
resp.TypeName = req.ProviderTypeName + "_teams"
|
resp.TypeName = req.ProviderTypeName + "_teams"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *TeamsDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
var teamSchemaAttributes = schema.ListNestedAttribute{
|
||||||
resp.Schema = schema.Schema{
|
|
||||||
Attributes: map[string]schema.Attribute{
|
|
||||||
"elements": schema.ListNestedAttribute{
|
|
||||||
Computed: true,
|
Computed: true,
|
||||||
MarkdownDescription: "The list of teams for an organization.",
|
MarkdownDescription: "The list of teams for an organization.",
|
||||||
NestedObject: schema.NestedAttributeObject{
|
NestedObject: schema.NestedAttributeObject{
|
||||||
|
@ -86,7 +83,12 @@ func (d *TeamsDataSource) Schema(ctx context.Context, req datasource.SchemaReque
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
|
|
||||||
|
func (d *TeamsDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||||
|
resp.Schema = schema.Schema{
|
||||||
|
Attributes: map[string]schema.Attribute{
|
||||||
|
"elements": teamSchemaAttributes,
|
||||||
"organization_name": schema.StringAttribute{
|
"organization_name": schema.StringAttribute{
|
||||||
MarkdownDescription: "The name of the organization the teams are a part of.",
|
MarkdownDescription: "The name of the organization the teams are a part of.",
|
||||||
Required: true,
|
Required: true,
|
||||||
|
@ -100,6 +102,19 @@ 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 {
|
||||||
|
return &TeamDataSourceModel{
|
||||||
|
CanCreateOrgRepo: types.BoolValue(team.CanCreateOrgRepo),
|
||||||
|
Description: types.StringValue(team.Description),
|
||||||
|
Id: types.Int64Value(team.Id),
|
||||||
|
IncludesAllRepositories: types.BoolValue(team.IncludesAllRepositories),
|
||||||
|
Name: types.StringValue(team.Name),
|
||||||
|
Permission: types.StringValue(team.Permission),
|
||||||
|
Units: make([]types.String, len(team.Units)),
|
||||||
|
UnitsMap: make(map[string]types.String),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (d *TeamsDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
func (d *TeamsDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||||
var data TeamsDataSourceModel
|
var data TeamsDataSourceModel
|
||||||
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
|
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
|
||||||
|
@ -113,16 +128,7 @@ func (d *TeamsDataSource) Read(ctx context.Context, req datasource.ReadRequest,
|
||||||
}
|
}
|
||||||
teamsList := make([]TeamDataSourceModel, len(teams))
|
teamsList := make([]TeamDataSourceModel, len(teams))
|
||||||
for i, team := range teams {
|
for i, team := range teams {
|
||||||
teamsList[i] = TeamDataSourceModel{
|
teamsList[i] = *populateTeamDataSourceModel(&team)
|
||||||
CanCreateOrgRepo: types.BoolValue(team.CanCreateOrgRepo),
|
|
||||||
Description: types.StringValue(team.Description),
|
|
||||||
Id: types.Int64Value(team.Id),
|
|
||||||
IncludesAllRepositories: types.BoolValue(team.IncludesAllRepositories),
|
|
||||||
Name: types.StringValue(team.Name),
|
|
||||||
Permission: types.StringValue(team.Permission),
|
|
||||||
Units: make([]types.String, len(team.Units)),
|
|
||||||
UnitsMap: make(map[string]types.String),
|
|
||||||
}
|
|
||||||
slices.Sort(team.Units)
|
slices.Sort(team.Units)
|
||||||
for j, unit := range team.Units {
|
for j, unit := range team.Units {
|
||||||
teamsList[i].Units[j] = types.StringValue(unit)
|
teamsList[i].Units[j] = types.StringValue(unit)
|
||||||
|
|
|
@ -53,14 +53,7 @@ func (d *UsersDataSource) Metadata(ctx context.Context, req datasource.MetadataR
|
||||||
resp.TypeName = req.ProviderTypeName + "_users"
|
resp.TypeName = req.ProviderTypeName + "_users"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *UsersDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
var userSchemaAttributes = map[string]schema.Attribute{
|
||||||
resp.Schema = schema.Schema{
|
|
||||||
Attributes: map[string]schema.Attribute{
|
|
||||||
"elements": schema.ListNestedAttribute{
|
|
||||||
Computed: true,
|
|
||||||
MarkdownDescription: "The list of users.",
|
|
||||||
NestedObject: schema.NestedAttributeObject{
|
|
||||||
Attributes: map[string]schema.Attribute{
|
|
||||||
"active": schema.BoolAttribute{
|
"active": schema.BoolAttribute{
|
||||||
Computed: true,
|
Computed: true,
|
||||||
MarkdownDescription: "Whether the user is active or not.",
|
MarkdownDescription: "Whether the user is active or not.",
|
||||||
|
@ -155,7 +148,16 @@ func (d *UsersDataSource) Schema(ctx context.Context, req datasource.SchemaReque
|
||||||
Computed: true,
|
Computed: true,
|
||||||
MarkdownDescription: "The user's advertised website.",
|
MarkdownDescription: "The user's advertised website.",
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
|
|
||||||
|
func (d *UsersDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||||
|
resp.Schema = schema.Schema{
|
||||||
|
Attributes: map[string]schema.Attribute{
|
||||||
|
"elements": schema.ListNestedAttribute{
|
||||||
|
Computed: true,
|
||||||
|
MarkdownDescription: "The list of users.",
|
||||||
|
NestedObject: schema.NestedAttributeObject{
|
||||||
|
Attributes: userSchemaAttributes,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -167,20 +169,8 @@ func (d *UsersDataSource) Configure(ctx context.Context, req datasource.Configur
|
||||||
d.client, _ = req.ProviderData.(*client.Client)
|
d.client, _ = req.ProviderData.(*client.Client)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *UsersDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
func populateUserDataSourceModel(user *client.User) *UserDataSourceModel {
|
||||||
var data UsersDataSourceModel
|
return &UserDataSourceModel{
|
||||||
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
|
|
||||||
if resp.Diagnostics.HasError() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
users, err := d.client.UsersList(ctx)
|
|
||||||
if err != nil {
|
|
||||||
resp.Diagnostics.AddError("ListUsers", fmt.Sprintf("failed to list users: %s", err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
userList := make([]UserDataSourceModel, len(users))
|
|
||||||
for i, user := range users {
|
|
||||||
userList[i] = UserDataSourceModel{
|
|
||||||
Active: types.BoolValue(user.Active),
|
Active: types.BoolValue(user.Active),
|
||||||
AvatarUrl: types.StringValue(user.AvatarUrl),
|
AvatarUrl: types.StringValue(user.AvatarUrl),
|
||||||
Created: timetypes.NewRFC3339TimeValue(user.Created),
|
Created: timetypes.NewRFC3339TimeValue(user.Created),
|
||||||
|
@ -206,6 +196,22 @@ func (d *UsersDataSource) Read(ctx context.Context, req datasource.ReadRequest,
|
||||||
Website: types.StringValue(user.Website),
|
Website: types.StringValue(user.Website),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *UsersDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||||
|
var data UsersDataSourceModel
|
||||||
|
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
|
||||||
|
if resp.Diagnostics.HasError() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
users, err := d.client.UsersList(ctx)
|
||||||
|
if err != nil {
|
||||||
|
resp.Diagnostics.AddError("ListUsers", fmt.Sprintf("failed to list users: %s", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
userList := make([]UserDataSourceModel, len(users))
|
||||||
|
for i, user := range users {
|
||||||
|
userList[i] = *populateUserDataSourceModel(&user)
|
||||||
|
}
|
||||||
data.Elements = userList
|
data.Elements = userList
|
||||||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
|
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue