Show forge icons in UI (#987)

This commit is contained in:
qwerty287 2022-06-17 20:14:01 +02:00 committed by GitHub
parent 99f1b70570
commit 42c745362b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 84 additions and 4 deletions

View file

@ -60,6 +60,11 @@ func New(opts *Opts) (remote.Remote, error) {
// TODO: add checks
}
// Name returns the string name of this driver
func (c *config) Name() string {
return "bitbucket"
}
// Login authenticates an account with Bitbucket using the oauth2 protocol. The
// Bitbucket account details are returned when the user is successfully authenticated.
func (c *config) Login(ctx context.Context, w http.ResponseWriter, req *http.Request) (*model.User, error) {

View file

@ -104,6 +104,11 @@ func New(opts Opts) (remote.Remote, error) {
return config, nil
}
// Name returns the string name of this driver
func (c *Config) Name() string {
return "stash"
}
func (c *Config) Login(ctx context.Context, res http.ResponseWriter, req *http.Request) (*model.User, error) {
requestToken, u, err := c.Consumer.GetRequestTokenAndUrl("oob")
if err != nil {

View file

@ -74,6 +74,11 @@ type Coding struct {
SkipVerify bool
}
// Name returns the string name of this driver
func (c *Coding) Name() string {
return "coding"
}
// Login authenticates the session and returns the
// remote user details.
func (c *Coding) Login(ctx context.Context, res http.ResponseWriter, req *http.Request) (*model.User, error) {

View file

@ -79,6 +79,11 @@ func New(opts Opts) (remote.Remote, error) {
}, nil
}
// Name returns the string name of this driver
func (c *Gitea) Name() string {
return "gitea"
}
// Login authenticates an account with Gitea using basic authentication. The
// Gitea account details are returned when the user is successfully authenticated.
func (c *Gitea) Login(ctx context.Context, w http.ResponseWriter, req *http.Request) (*model.User, error) {

View file

@ -78,6 +78,11 @@ type client struct {
MergeRef bool
}
// Name returns the string name of this driver
func (c *client) Name() string {
return "github"
}
// Login authenticates the session and returns the remote user details.
func (c *client) Login(ctx context.Context, res http.ResponseWriter, req *http.Request) (*model.User, error) {
config := c.newConfig(req)

View file

@ -69,6 +69,11 @@ func New(opts Opts) (remote.Remote, error) {
}, nil
}
// Name returns the string name of this driver
func (g *Gitlab) Name() string {
return "gitlab"
}
// Login authenticates the session and returns the
// remote user details.
func (g *Gitlab) Login(ctx context.Context, res http.ResponseWriter, req *http.Request) (*model.User, error) {

View file

@ -67,6 +67,11 @@ func New(opts Opts) (remote.Remote, error) {
}, nil
}
// Name returns the string name of this driver
func (c *client) Name() string {
return "gogs"
}
// Login authenticates an account with Gogs using basic authentication. The
// Gogs account details are returned when the user is successfully authenticated.
func (c *client) Login(ctx context.Context, res http.ResponseWriter, req *http.Request) (*model.User, error) {

View file

@ -1,4 +1,4 @@
// Code generated by mockery v1.0.0. DO NOT EDIT.
// Code generated by mockery v2.13.1. DO NOT EDIT.
package mocks
@ -191,6 +191,20 @@ func (_m *Remote) Login(ctx context.Context, w http.ResponseWriter, r *http.Requ
return r0, r1
}
// Name provides a mock function with given fields:
func (_m *Remote) Name() string {
ret := _m.Called()
var r0 string
if rf, ok := ret.Get(0).(func() string); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(string)
}
return r0
}
// Netrc provides a mock function with given fields: u, r
func (_m *Remote) Netrc(u *model.User, r *model.Repo) (*model.Netrc, error) {
ret := _m.Called(u, r)
@ -319,3 +333,18 @@ func (_m *Remote) Teams(ctx context.Context, u *model.User) ([]*model.Team, erro
return r0, r1
}
type mockConstructorTestingTNewRemote interface {
mock.TestingT
Cleanup(func())
}
// NewRemote creates a new instance of Remote. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
func NewRemote(t mockConstructorTestingTNewRemote) *Remote {
mock := &Remote{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}

View file

@ -27,6 +27,9 @@ import (
// TODO: add Driver() who return source forge back
type Remote interface {
// Name returns the string name of this driver
Name() string
// Login authenticates the session and returns the
// remote user details.
Login(ctx context.Context, w http.ResponseWriter, r *http.Request) (*model.User, error)

View file

@ -51,6 +51,7 @@ func Config(c *gin.Context) {
"syncing": syncing,
"docs": server.Config.Server.Docs,
"version": version.String(),
"forge": server.Config.Services.Remote.Name(),
}
// default func map with json parser.
@ -76,4 +77,5 @@ window.WOODPECKER_SYNC = {{ .syncing }};
window.WOODPECKER_CSRF = "{{ .csrf }}";
window.WOODPECKER_VERSION = "{{ .version }}";
window.WOODPECKER_DOCS = "{{ .docs }}";
window.WOODPECKER_FORGE = "{{ .forge }}";
`

View file

@ -21,7 +21,9 @@
<i-ph-prohibit v-else-if="name === 'status-skipped'" class="h-8 w-8" />
<i-entypo-dots-two-vertical v-else-if="name === 'status-started'" class="h-8 w-8" />
<i-ph-check-circle v-else-if="name === 'status-success'" class="h-8 w-8" />
<i-cib-gitea v-else-if="name === 'gitea'" class="h-8 w-8" />
<i-simple-icons-gitea v-else-if="name === 'gitea'" class="h-8 w-8" />
<i-ph-gitlab-logo-simple-fill v-else-if="name === 'gitlab'" class="h-8 w-8" />
<i-mdi-bitbucket v-else-if="name === 'bitbucket'" class="h-8 w-8" />
<i-vaadin-question-circle-o v-else-if="name === 'question'" class="h-6 w-6" />
<i-ic-twotone-add v-else-if="name === 'plus'" class="h-6 w-6" />
<i-mdi-format-list-bulleted v-else-if="name === 'list'" class="h-6 w-6" />
@ -64,6 +66,8 @@ export type IconNames =
| 'status-started'
| 'status-success'
| 'gitea'
| 'gitlab'
| 'bitbucket'
| 'question'
| 'list'
| 'loading'

View file

@ -7,6 +7,7 @@ declare global {
WOODPECKER_DOCS: string | undefined;
WOODPECKER_VERSION: string | undefined;
WOODPECKER_CSRF: string | undefined;
WOODPECKER_FORGE: string | undefined;
}
}
@ -16,4 +17,5 @@ export default () => ({
docs: window.WOODPECKER_DOCS || null,
version: window.WOODPECKER_VERSION,
csrf: window.WOODPECKER_CSRF || null,
forge: window.WOODPECKER_FORGE || null,
});

View file

@ -13,7 +13,10 @@
target="_blank"
class="flex ml-4 p-1 rounded-full text-color hover:bg-gray-200 hover:text-gray-700 dark:hover:bg-gray-600"
>
<Icon v-if="repo.link_url.startsWith('https://github.com/')" name="github" />
<Icon v-if="forge === 'github'" name="github" />
<Icon v-else-if="forge === 'gitea'" name="gitea" />
<Icon v-else-if="forge === 'gitlab'" name="gitlab" />
<Icon v-else-if="forge === 'bitbucket' || forge === 'stash'" name="bitbucket" />
<Icon v-else name="repo" />
</a>
<IconButton v-if="repoPermissions.admin" class="ml-2" :to="{ name: 'repo-settings' }" icon="settings" />
@ -41,6 +44,7 @@ import Tab from '~/components/tabs/Tab.vue';
import Tabs from '~/components/tabs/Tabs.vue';
import useApiClient from '~/compositions/useApiClient';
import useAuthentication from '~/compositions/useAuthentication';
import useConfig from '~/compositions/useConfig';
import useNotifications from '~/compositions/useNotifications';
import { RepoPermissions } from '~/lib/api/types';
import BuildStore from '~/store/builds';
@ -79,6 +83,7 @@ export default defineComponent({
const router = useRouter();
const i18n = useI18n();
const { forge } = useConfig();
const repo = repoStore.getRepo(repoOwner, repoName);
const repoPermissions = ref<RepoPermissions>();
const builds = buildStore.getSortedBuilds(repoOwner, repoName);
@ -129,7 +134,7 @@ export default defineComponent({
},
});
return { repo, repoPermissions, badgeUrl, activeTab };
return { repo, repoPermissions, badgeUrl, activeTab, forge };
},
});
</script>