diff --git a/server/remote/bitbucket/bitbucket.go b/server/remote/bitbucket/bitbucket.go index 759522070..6769c4180 100644 --- a/server/remote/bitbucket/bitbucket.go +++ b/server/remote/bitbucket/bitbucket.go @@ -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) { diff --git a/server/remote/bitbucketserver/bitbucketserver.go b/server/remote/bitbucketserver/bitbucketserver.go index b317079ca..5f395bb64 100644 --- a/server/remote/bitbucketserver/bitbucketserver.go +++ b/server/remote/bitbucketserver/bitbucketserver.go @@ -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 { diff --git a/server/remote/coding/coding.go b/server/remote/coding/coding.go index 7cf2c620d..d5882d075 100644 --- a/server/remote/coding/coding.go +++ b/server/remote/coding/coding.go @@ -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) { diff --git a/server/remote/gitea/gitea.go b/server/remote/gitea/gitea.go index d04d0eb93..33af4e266 100644 --- a/server/remote/gitea/gitea.go +++ b/server/remote/gitea/gitea.go @@ -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) { diff --git a/server/remote/github/github.go b/server/remote/github/github.go index 34b11a8bf..96c016310 100644 --- a/server/remote/github/github.go +++ b/server/remote/github/github.go @@ -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) diff --git a/server/remote/gitlab/gitlab.go b/server/remote/gitlab/gitlab.go index 70be780ca..ebe7427e5 100644 --- a/server/remote/gitlab/gitlab.go +++ b/server/remote/gitlab/gitlab.go @@ -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) { diff --git a/server/remote/gogs/gogs.go b/server/remote/gogs/gogs.go index ef18f88d1..6d24ab3a5 100644 --- a/server/remote/gogs/gogs.go +++ b/server/remote/gogs/gogs.go @@ -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) { diff --git a/server/remote/mocks/remote.go b/server/remote/mocks/remote.go index 3fc5544ee..f0e4b94b4 100644 --- a/server/remote/mocks/remote.go +++ b/server/remote/mocks/remote.go @@ -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 +} diff --git a/server/remote/remote.go b/server/remote/remote.go index e79ba57be..a5b18316c 100644 --- a/server/remote/remote.go +++ b/server/remote/remote.go @@ -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) diff --git a/server/web/config.go b/server/web/config.go index 9dd74ce68..3847aa35d 100644 --- a/server/web/config.go +++ b/server/web/config.go @@ -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 }}"; ` diff --git a/web/src/components/atomic/Icon.vue b/web/src/components/atomic/Icon.vue index f1c957243..54c190136 100644 --- a/web/src/components/atomic/Icon.vue +++ b/web/src/components/atomic/Icon.vue @@ -21,7 +21,9 @@ - + + + @@ -64,6 +66,8 @@ export type IconNames = | 'status-started' | 'status-success' | 'gitea' + | 'gitlab' + | 'bitbucket' | 'question' | 'list' | 'loading' diff --git a/web/src/compositions/useConfig.ts b/web/src/compositions/useConfig.ts index bfed43eae..d019cb57e 100644 --- a/web/src/compositions/useConfig.ts +++ b/web/src/compositions/useConfig.ts @@ -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, }); diff --git a/web/src/views/repo/RepoWrapper.vue b/web/src/views/repo/RepoWrapper.vue index 1550fee88..8ea8c6e58 100644 --- a/web/src/views/repo/RepoWrapper.vue +++ b/web/src/views/repo/RepoWrapper.vue @@ -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" > - + + + + @@ -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(); const builds = buildStore.getSortedBuilds(repoOwner, repoName); @@ -129,7 +134,7 @@ export default defineComponent({ }, }); - return { repo, repoPermissions, badgeUrl, activeTab }; + return { repo, repoPermissions, badgeUrl, activeTab, forge }; }, });