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

Hide PR tab if PRs are disabled #3004

Merged
merged 3 commits into from
Dec 24, 2023
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
3 changes: 3 additions & 0 deletions cmd/server/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4135,6 +4135,9 @@ const docTemplate = `{
"owner": {
"type": "string"
},
"pr_enabled": {
"type": "boolean"
},
"private": {
"type": "boolean"
},
Expand Down
12 changes: 6 additions & 6 deletions pipeline/rpc/proto/woodpecker.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pipeline/rpc/proto/woodpecker_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/forge/bitbucket/bitbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ func (c *config) PullRequests(ctx context.Context, u *model.User, r *model.Repo,
if err != nil {
return nil, err
}
result := []*model.PullRequest{}
var result []*model.PullRequest
for _, pullRequest := range pullRequests {
result = append(result, &model.PullRequest{
Index: model.ForgeRemoteID(strconv.Itoa(int(pullRequest.ID))),
Expand Down
1 change: 1 addition & 0 deletions server/forge/bitbucket/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func convertRepo(from *internal.Repo, perm *internal.RepoPerm) *model.Repo {
SCMKind: model.SCMKind(from.Scm),
Branch: from.Mainbranch.Name,
Perm: convertPerm(perm),
PREnabled: true,
}
if repo.SCMKind == model.RepoHg {
repo.Branch = "default"
Expand Down
1 change: 1 addition & 0 deletions server/forge/gitea/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func toRepo(from *gitea.Repository) *model.Repo {
CloneSSH: from.SSHURL,
Branch: from.DefaultBranch,
Perm: toPerm(from.Permissions),
PREnabled: from.HasPullRequests,
}
}

Expand Down
2 changes: 2 additions & 0 deletions server/forge/github/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func convertRepo(from *github.Repository) *model.Repo {
Avatar: from.GetOwner().GetAvatarURL(),
Perm: convertPerm(from.GetPermissions()),
SCMKind: model.RepoGit,
PREnabled: true,
}
return repo
}
Expand Down Expand Up @@ -152,6 +153,7 @@ func convertRepoHook(eventRepo *github.PushEventRepository) *model.Repo {
CloneSSH: eventRepo.GetSSHURL(),
Branch: eventRepo.GetDefaultBranch(),
SCMKind: model.RepoGit,
PREnabled: true,
}
if repo.FullName == "" {
repo.FullName = repo.Owner + "/" + repo.Name
Expand Down
1 change: 1 addition & 0 deletions server/forge/gitlab/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func (g *GitLab) convertGitLabRepo(_repo *gitlab.Project) (*model.Repo, error) {
Push: isWrite(_repo),
Admin: isAdmin(_repo),
},
PREnabled: _repo.MergeRequestsEnabled,
}

if len(repo.Avatar) != 0 && !strings.HasPrefix(repo.Avatar, "http") {
Expand Down
2 changes: 1 addition & 1 deletion server/forge/mocks/forge.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion server/model/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
CloneSSH string `json:"clone_url_ssh" xorm:"varchar(1000) 'repo_clone_ssh'"`
Branch string `json:"default_branch,omitempty" xorm:"varchar(500) 'repo_branch'"`
SCMKind SCMKind `json:"scm,omitempty" xorm:"varchar(50) 'repo_scm'"`
PREnabled bool `json:"pr_enabled" xorm:"DEFAULT TRUE 'repo_pr_enabled'"`
Timeout int64 `json:"timeout,omitempty" xorm:"repo_timeout"`
Visibility RepoVisibility `json:"visibility" xorm:"varchar(10) 'repo_visibility'"`
IsSCMPrivate bool `json:"private" xorm:"repo_private"`
Expand Down Expand Up @@ -66,7 +67,7 @@
func ParseRepo(str string) (user, repo string, err error) {
parts := strings.Split(str, "/")
if len(parts) != 2 {
err = fmt.Errorf("Error: Invalid or missing repository. eg octocat/hello-world")
err = fmt.Errorf("error: Invalid or missing repository. eg octocat/hello-world")

Check warning on line 70 in server/model/repo.go

View check run for this annotation

Codecov / codecov/patch

server/model/repo.go#L70

Added line #L70 was not covered by tests
return
}
user = parts[0]
Expand All @@ -85,6 +86,7 @@
r.Avatar = from.Avatar
r.ForgeURL = from.ForgeURL
r.SCMKind = from.SCMKind
r.PREnabled = from.PREnabled

Check warning on line 89 in server/model/repo.go

View check run for this annotation

Codecov / codecov/patch

server/model/repo.go#L89

Added line #L89 was not covered by tests
if len(from.Clone) > 0 {
r.Clone = from.Clone
}
Expand Down
2 changes: 1 addition & 1 deletion server/store/mocks/store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions web/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,19 @@ declare module 'vue' {
IMdiBitbucket: typeof import('~icons/mdi/bitbucket')['default']
IMdiChevronRight: typeof import('~icons/mdi/chevron-right')['default']
IMdiClockTimeEightOutline: typeof import('~icons/mdi/clock-time-eight-outline')['default']
IMdiCloseThick: typeof import('~icons/mdi/close-thick')['default']
IMdiErrorOutline: typeof import('~icons/mdi/error-outline')['default']
IMdiFormatListBulleted: typeof import('~icons/mdi/format-list-bulleted')['default']
IMdiGestureTap: typeof import('~icons/mdi/gesture-tap')['default']
IMdiGithub: typeof import('~icons/mdi/github')['default']
IMdiLoading: typeof import('~icons/mdi/loading')['default']
IMdiPlay: typeof import('~icons/mdi/play')['default']
IMdiRadioboxBlank: typeof import('~icons/mdi/radiobox-blank')['default']
IMdiRadioboxIndeterminateVariant: typeof import('~icons/mdi/radiobox-indeterminate-variant')['default']
IMdiSourceBranch: typeof import('~icons/mdi/source-branch')['default']
IMdisourceCommit: typeof import('~icons/mdi/source-commit')['default']
IMdiSourcePull: typeof import('~icons/mdi/source-pull')['default']
IMdiStop: typeof import('~icons/mdi/stop')['default']
IMdiSync: typeof import('~icons/mdi/sync')['default']
IMdiTagOutline: typeof import('~icons/mdi/tag-outline')['default']
InputField: typeof import('./src/components/form/InputField.vue')['default']
Expand Down
5 changes: 4 additions & 1 deletion web/src/lib/api/types/repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ export type Repo = {
forge_remote_id: string;

// The source control management being used.
// Currently this is either 'git' or 'hg' (Mercurial).
// Currently, this is either 'git' or 'hg' (Mercurial).
scm: string;

// Whether the forge repo has PRs enabled.
pr_enabled: boolean;

// The id of the organization that owns the repository.
org_id: number;

Expand Down
3 changes: 3 additions & 0 deletions web/src/views/repo/RepoPullRequest.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const repoPermissions = inject<Ref<RepoPermissions>>('repo-permissions');
if (!repo || !repoPermissions) {
throw new Error('Unexpected: "repo" and "repoPermissions" should be provided at this place');
}
if (!repo.value.pr_enabled || !repo.value.allow_pr) {
throw new Error('Unexpected: pull requests are disabled for repo');
}

const allPipelines = inject<Ref<Pipeline[]>>('pipelines');
const pipelines = computed(
Expand Down
3 changes: 3 additions & 0 deletions web/src/views/repo/RepoPullRequests.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ const repo = inject<Ref<Repo>>('repo');
if (!repo) {
throw new Error('Unexpected: "repo" should be provided at this place');
}
if (!repo.value.pr_enabled || !repo.value.allow_pr) {
throw new Error('Unexpected: pull requests are disabled for repo');
}

async function loadPullRequests(page: number): Promise<PullRequest[]> {
if (!repo) {
Expand Down
2 changes: 1 addition & 1 deletion web/src/views/repo/RepoWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

<Tab id="activity" :title="$t('repo.activity')" />
<Tab id="branches" :title="$t('repo.branches')" />
<Tab id="pull_requests" :title="$t('repo.pull_requests')" />
<Tab v-if="repo.pr_enabled && repo.allow_pr" id="pull_requests" :title="$t('repo.pull_requests')" />

<router-view />
</Scaffold>
Expand Down