Skip to content

Commit

Permalink
Refactor: Rename server/helpers -> server/shared
Browse files Browse the repository at this point in the history
  • Loading branch information
cognifloyd committed Sep 22, 2021
1 parent cceaf44 commit 39e7f13
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 43 deletions.
22 changes: 11 additions & 11 deletions server/api/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
"github.com/woodpecker-ci/woodpecker/model"
"github.com/woodpecker-ci/woodpecker/router/middleware/session"
"github.com/woodpecker-ci/woodpecker/server"
"github.com/woodpecker-ci/woodpecker/server/helpers"
"github.com/woodpecker-ci/woodpecker/server/shared"
)

func GetBuilds(c *gin.Context) {
Expand Down Expand Up @@ -206,18 +206,18 @@ func DeleteBuild(c *gin.Context) {
for _, proc := range procs {
if proc.State == model.StatusPending {
if proc.PPID != 0 {
if _, err = helpers.UpdateProcToStatusSkipped(store.FromContext(c), *proc, 0); err != nil {
if _, err = shared.UpdateProcToStatusSkipped(store.FromContext(c), *proc, 0); err != nil {
log.Printf("error: done: cannot update proc_id %d state: %s", proc.ID, err)
}
} else {
if _, err = helpers.UpdateProcToStatusKilled(store.FromContext(c), *proc); err != nil {
if _, err = shared.UpdateProcToStatusKilled(store.FromContext(c), *proc); err != nil {
log.Printf("error: done: cannot update proc_id %d state: %s", proc.ID, err)
}
}
}
}

killedBuild, err := helpers.UpdateToStatusKilled(store.FromContext(c), *build)
killedBuild, err := shared.UpdateToStatusKilled(store.FromContext(c), *build)
if err != nil {
c.AbortWithError(500, err)
return
Expand Down Expand Up @@ -272,7 +272,7 @@ func PostApproval(c *gin.Context) {
return
}

if build, err = helpers.UpdateToStatusPending(store.FromContext(c), *build, user.Login); err != nil {
if build, err = shared.UpdateToStatusPending(store.FromContext(c), *build, user.Login); err != nil {
c.String(500, "error updating build. %s", err)
return
}
Expand Down Expand Up @@ -303,7 +303,7 @@ func PostApproval(c *gin.Context) {
yamls = append(yamls, &remote.FileMeta{Data: []byte(y.Data), Name: y.Name})
}

b := helpers.ProcBuilder{
b := shared.ProcBuilder{
Repo: repo,
Curr: build,
Last: last,
Expand All @@ -316,12 +316,12 @@ func PostApproval(c *gin.Context) {
}
buildItems, err := b.Build()
if err != nil {
if _, err = helpers.UpdateToStatusError(store.FromContext(c), *build, err); err != nil {
if _, err = shared.UpdateToStatusError(store.FromContext(c), *build, err); err != nil {
logrus.Errorf("Error setting error status of build for %s#%d. %s", repo.FullName, build.Number, err)
}
return
}
build = helpers.SetBuildStepsOnBuild(b.Curr, buildItems)
build = shared.SetBuildStepsOnBuild(b.Curr, buildItems)

err = store.FromContext(c).ProcCreate(build.Procs)
if err != nil {
Expand Down Expand Up @@ -366,7 +366,7 @@ func PostDecline(c *gin.Context) {
return
}

if _, err = helpers.UpdateToStatusDeclined(store.FromContext(c), *build, user.Login); err != nil {
if _, err = shared.UpdateToStatusDeclined(store.FromContext(c), *build, user.Login); err != nil {
c.String(500, "error updating build. %s", err)
return
}
Expand Down Expand Up @@ -512,7 +512,7 @@ func PostBuild(c *gin.Context) {
yamls = append(yamls, &remote.FileMeta{Data: []byte(y.Data), Name: y.Name})
}

b := helpers.ProcBuilder{
b := shared.ProcBuilder{
Repo: repo,
Curr: build,
Last: last,
Expand All @@ -532,7 +532,7 @@ func PostBuild(c *gin.Context) {
c.JSON(500, build)
return
}
build = helpers.SetBuildStepsOnBuild(b.Curr, buildItems)
build = shared.SetBuildStepsOnBuild(b.Curr, buildItems)

err = store.FromContext(c).ProcCreate(build.Procs)
if err != nil {
Expand Down
18 changes: 9 additions & 9 deletions server/api/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import (
"github.com/woodpecker-ci/woodpecker/cncd/pubsub"
"github.com/woodpecker-ci/woodpecker/cncd/queue"
"github.com/woodpecker-ci/woodpecker/server"
"github.com/woodpecker-ci/woodpecker/server/helpers"
"github.com/woodpecker-ci/woodpecker/server/shared"
)

var skipRe = regexp.MustCompile(`\[(?i:ci *skip|skip *ci)\]`)
Expand Down Expand Up @@ -161,7 +161,7 @@ func PostHook(c *gin.Context) {
}

// fetch the build file from the remote
configFetcher := helpers.NewConfigFetcher(remote_, user, repo, build)
configFetcher := shared.NewConfigFetcher(remote_, user, repo, build)
remoteYamlConfigs, err := configFetcher.Fetch()
if err != nil {
logrus.Errorf("error: %s: cannot find %s in %s: %s", repo.FullName, repo.Config, build.Ref, err)
Expand Down Expand Up @@ -243,7 +243,7 @@ func PostHook(c *gin.Context) {
// get the previous build so that we can send status change notifications
last, _ := store.GetBuildLastBefore(c, repo, build.Branch, build.ID)

b := helpers.ProcBuilder{
b := shared.ProcBuilder{
Repo: repo,
Curr: build,
Last: last,
Expand All @@ -256,12 +256,12 @@ func PostHook(c *gin.Context) {
}
buildItems, err := b.Build()
if err != nil {
if _, err = helpers.UpdateToStatusError(store.FromContext(c), *build, err); err != nil {
if _, err = shared.UpdateToStatusError(store.FromContext(c), *build, err); err != nil {
logrus.Errorf("Error setting error status of build for %s#%d. %s", repo.FullName, build.Number, err)
}
return
}
build = helpers.SetBuildStepsOnBuild(b.Curr, buildItems)
build = shared.SetBuildStepsOnBuild(b.Curr, buildItems)

err = store.FromContext(c).ProcCreate(build.Procs)
if err != nil {
Expand Down Expand Up @@ -302,7 +302,7 @@ func branchFiltered(build *model.Build, remoteYamlConfigs []*remote.FileMeta) (b
}

func zeroSteps(build *model.Build, remoteYamlConfigs []*remote.FileMeta) bool {
b := helpers.ProcBuilder{
b := shared.ProcBuilder{
Repo: &model.Repo{},
Curr: build,
Last: &model.Build{},
Expand Down Expand Up @@ -332,7 +332,7 @@ func findOrPersistPipelineConfig(repo *model.Repo, build *model.Build, remoteYam
RepoID: build.RepoID,
Data: string(remoteYamlConfig.Data),
Hash: sha,
Name: helpers.SanitizePath(remoteYamlConfig.Name),
Name: shared.SanitizePath(remoteYamlConfig.Name),
}
err = server.Config.Storage.Config.ConfigCreate(conf)
if err != nil {
Expand Down Expand Up @@ -374,7 +374,7 @@ func publishToTopic(c *gin.Context, build *model.Build, repo *model.Repo, event
server.Config.Services.Pubsub.Publish(c, "topic/events", message)
}

func queueBuild(build *model.Build, repo *model.Repo, buildItems []*helpers.BuildItem) {
func queueBuild(build *model.Build, repo *model.Repo, buildItems []*shared.BuildItem) {
var tasks []*queue.Task
for _, item := range buildItems {
if item.Proc.State == model.StatusSkipped {
Expand Down Expand Up @@ -404,7 +404,7 @@ func queueBuild(build *model.Build, repo *model.Repo, buildItems []*helpers.Buil
server.Config.Services.Queue.PushAtOnce(context.Background(), tasks)
}

func taskIds(dependsOn []string, buildItems []*helpers.BuildItem) []string {
func taskIds(dependsOn []string, buildItems []*shared.BuildItem) []string {
taskIds := []string{}
for _, dep := range dependsOn {
for _, buildItem := range buildItems {
Expand Down
10 changes: 5 additions & 5 deletions server/api/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/woodpecker-ci/woodpecker/model"
"github.com/woodpecker-ci/woodpecker/remote"
"github.com/woodpecker-ci/woodpecker/router/middleware/session"
"github.com/woodpecker-ci/woodpecker/server/helpers"
"github.com/woodpecker-ci/woodpecker/server/shared"
"github.com/woodpecker-ci/woodpecker/shared/token"
"github.com/woodpecker-ci/woodpecker/store"
)
Expand All @@ -48,11 +48,11 @@ func GetFeed(c *gin.Context) {

config := ToConfig(c)

sync := helpers.Syncer{
sync := shared.Syncer{
Remote: remote.FromContext(c),
Store: store.FromContext(c),
Perms: store.FromContext(c),
Match: helpers.NamespaceFilter(config.OwnersWhitelist),
Match: shared.NamespaceFilter(config.OwnersWhitelist),
}
if err := sync.Sync(user); err != nil {
logrus.Debugf("sync error: %s: %s", user.Login, err)
Expand Down Expand Up @@ -93,11 +93,11 @@ func GetRepos(c *gin.Context) {

config := ToConfig(c)

sync := helpers.Syncer{
sync := shared.Syncer{
Remote: remote.FromContext(c),
Store: store.FromContext(c),
Perms: store.FromContext(c),
Match: helpers.NamespaceFilter(config.OwnersWhitelist),
Match: shared.NamespaceFilter(config.OwnersWhitelist),
}

if err := sync.Sync(user); err != nil {
Expand Down
14 changes: 7 additions & 7 deletions server/grpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
"github.com/woodpecker-ci/woodpecker/cncd/pubsub"
"github.com/woodpecker-ci/woodpecker/cncd/queue"
"github.com/woodpecker-ci/woodpecker/server"
"github.com/woodpecker-ci/woodpecker/server/helpers"
"github.com/woodpecker-ci/woodpecker/server/shared"

"github.com/woodpecker-ci/woodpecker/model"
"github.com/woodpecker-ci/woodpecker/remote"
Expand Down Expand Up @@ -139,7 +139,7 @@ func (s *RPC) Update(c context.Context, id string, state rpc.State) error {
return err
}

if proc, err = helpers.UpdateProcStatus(s.store, *proc, state, build.Started); err != nil {
if proc, err = shared.UpdateProcStatus(s.store, *proc, state, build.Started); err != nil {
log.Printf("error: rpc.update: cannot update proc: %s", err)
}

Expand Down Expand Up @@ -266,7 +266,7 @@ func (s *RPC) Init(c context.Context, id string, state rpc.State) error {
}

if build.Status == model.StatusPending {
if build, err = helpers.UpdateToStatusRunning(s.store, *build, state.Started); err != nil {
if build, err = shared.UpdateToStatusRunning(s.store, *build, state.Started); err != nil {
log.Printf("error: init: cannot update build_id %d state: %s", build.ID, err)
}
}
Expand All @@ -286,7 +286,7 @@ func (s *RPC) Init(c context.Context, id string, state rpc.State) error {
s.pubsub.Publish(c, "topic/events", message)
}()

_, err = helpers.UpdateProcToStatusStarted(s.store, *proc, state)
_, err = shared.UpdateProcToStatusStarted(s.store, *proc, state)
return err
}

Expand Down Expand Up @@ -315,7 +315,7 @@ func (s *RPC) Done(c context.Context, id string, state rpc.State) error {
return err
}

if proc, err = helpers.UpdateProcStatusToDone(s.store, *proc, state); err != nil {
if proc, err = shared.UpdateProcStatusToDone(s.store, *proc, state); err != nil {
log.Printf("error: done: cannot update proc_id %d state: %s", proc.ID, err)
}

Expand All @@ -333,7 +333,7 @@ func (s *RPC) Done(c context.Context, id string, state rpc.State) error {
s.completeChildrenIfParentCompleted(procs, proc)

if !isThereRunningStage(procs) {
if build, err = helpers.UpdateStatusToDone(s.store, *build, buildStatus(procs), proc.Stopped); err != nil {
if build, err = shared.UpdateStatusToDone(s.store, *build, buildStatus(procs), proc.Stopped); err != nil {
log.Printf("error: done: cannot update build_id %d final state: %s", build.ID, err)
}

Expand Down Expand Up @@ -384,7 +384,7 @@ func (s *RPC) Log(c context.Context, id string, line *rpc.Line) error {
func (s *RPC) completeChildrenIfParentCompleted(procs []*model.Proc, completedProc *model.Proc) {
for _, p := range procs {
if p.Running() && p.PPID == completedProc.PID {
if _, err := helpers.UpdateProcToStatusSkipped(s.store, *p, completedProc.Stopped); err != nil {
if _, err := shared.UpdateProcToStatusSkipped(s.store, *p, completedProc.Stopped); err != nil {
log.Printf("error: done: cannot update proc_id %d child state: %s", p.ID, err)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package helpers
package shared

import (
"time"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package helpers
package shared

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package helpers
package shared

import (
"strings"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package helpers_test
package shared_test

import (
"fmt"
Expand All @@ -9,7 +9,7 @@ import (
"github.com/woodpecker-ci/woodpecker/model"
"github.com/woodpecker-ci/woodpecker/remote"
"github.com/woodpecker-ci/woodpecker/remote/mocks"
"github.com/woodpecker-ci/woodpecker/server/helpers"
"github.com/woodpecker-ci/woodpecker/server/shared"
)

func TestFetch(t *testing.T) {
Expand Down Expand Up @@ -179,7 +179,7 @@ func TestFetch(t *testing.T) {
r.On("File", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("File not found"))
r.On("Dir", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("Directory not found"))

configFetcher := helpers.NewConfigFetcher(
configFetcher := shared.NewConfigFetcher(
r,
&model.User{Token: "xxx"},
repo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package helpers
package shared

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package helpers
package shared

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package helpers
package shared

import (
"time"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package helpers
package shared

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package helpers
package shared

import (
"time"
Expand Down

0 comments on commit 39e7f13

Please sign in to comment.