Skip to content

Commit

Permalink
refactor: rename the source package to scm (#536)
Browse files Browse the repository at this point in the history
* refactor: rename the source package to scm

* refactor(cmd): rename source to scm

* refactor(scm): rename source to scm

* refactor: update env vars to be scm

* refactor(github): update source to scm in comments

* refactor(router): update the middleware naming for source to scm

* fix: add back the source flags to reduce breaking changes

Co-authored-by: Neal Coleman <[email protected]>
  • Loading branch information
Neal and kneal authored Nov 22, 2021
1 parent d42723a commit 1bf0240
Show file tree
Hide file tree
Showing 89 changed files with 465 additions and 463 deletions.
8 changes: 4 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# These are used by the ui service
# defined in the docker compose stack

# customize the location where you want users to provide feedack
# customize the location where you want users to provide feedback
#
# default: https://github.com/go-vela/ui/issues/new
# VELA_FEEDBACK_URL=
Expand Down Expand Up @@ -44,10 +44,10 @@ VELA_API=http://localhost:8080
# github web url (only required if using GitHub Enterprise)
#
# default: https://github.com
# VELA_SOURCE_ADDR=
# VELA_SCM_ADDR=

# github client id from oauth application
VELA_SOURCE_CLIENT=
VELA_SCM_CLIENT=

# github client secret from oauth application
VELA_SOURCE_SECRET=
VELA_SCM_SECRET=
8 changes: 4 additions & 4 deletions api/authenticate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/token"
"github.com/go-vela/server/source"
"github.com/go-vela/server/scm"
"github.com/go-vela/server/util"

"github.com/go-vela/types"
Expand Down Expand Up @@ -76,7 +76,7 @@ func Authenticate(c *gin.Context) {
code := c.Request.FormValue("code")
if len(code) == 0 {
// start the initial OAuth workflow
oAuthState, err = source.FromContext(c).Login(c.Writer, c.Request)
oAuthState, err = scm.FromContext(c).Login(c.Writer, c.Request)
if err != nil {
retErr := fmt.Errorf("unable to login user: %w", err)

Expand All @@ -87,7 +87,7 @@ func Authenticate(c *gin.Context) {
}

// complete the OAuth workflow and authenticates the user
newUser, err := source.FromContext(c).Authenticate(c.Writer, c.Request, oAuthState)
newUser, err := scm.FromContext(c).Authenticate(c.Writer, c.Request, oAuthState)
if err != nil {
retErr := fmt.Errorf("unable to authenticate user: %w", err)

Expand Down Expand Up @@ -308,7 +308,7 @@ func AuthenticateType(c *gin.Context) {
// the API.
func AuthenticateToken(c *gin.Context) {
// attempt to get user from source
u, err := source.FromContext(c).AuthenticateToken(c.Request)
u, err := scm.FromContext(c).AuthenticateToken(c.Request)
if err != nil {
retErr := fmt.Errorf("unable to authenticate user: %w", err)

Expand Down
26 changes: 13 additions & 13 deletions api/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/go-vela/server/router/middleware/executors"
"github.com/go-vela/server/router/middleware/repo"
"github.com/go-vela/server/router/middleware/user"
"github.com/go-vela/server/source"
"github.com/go-vela/server/scm"
"github.com/go-vela/server/util"

"github.com/go-vela/types"
Expand Down Expand Up @@ -163,7 +163,7 @@ func CreateBuild(c *gin.Context) {
// check if the build event is not pull_request
if !strings.EqualFold(input.GetEvent(), constants.EventPull) {
// send API call to capture list of files changed for the commit
files, err = source.FromContext(c).Changeset(u, r, input.GetCommit())
files, err = scm.FromContext(c).Changeset(u, r, input.GetCommit())
if err != nil {
// nolint: lll // ignore long line length due to error message
retErr := fmt.Errorf("unable to process webhook: failed to get changeset for %s: %w", r.GetFullName(), err)
Expand All @@ -188,7 +188,7 @@ func CreateBuild(c *gin.Context) {
}

// send API call to capture list of files changed for the pull request
files, err = source.FromContext(c).ChangesetPR(u, r, number)
files, err = scm.FromContext(c).ChangesetPR(u, r, number)
if err != nil {
// nolint: lll // ignore long line length due to error message
retErr := fmt.Errorf("unable to process webhook: failed to get changeset for %s: %w", r.GetFullName(), err)
Expand All @@ -200,7 +200,7 @@ func CreateBuild(c *gin.Context) {
}

// send API call to capture the pipeline configuration file
config, err := source.FromContext(c).ConfigBackoff(u, r, input.GetCommit())
config, err := scm.FromContext(c).ConfigBackoff(u, r, input.GetCommit())
if err != nil {
// nolint: lll // ignore long line length due to error message
retErr := fmt.Errorf("unable to get pipeline configuration for %s/%d: %w", r.GetFullName(), input.GetNumber(), err)
Expand Down Expand Up @@ -234,7 +234,7 @@ func CreateBuild(c *gin.Context) {
input.SetStatus(constants.StatusSuccess)

// send API call to set the status on the commit
err = source.FromContext(c).Status(u, input, r.GetOrg(), r.GetName())
err = scm.FromContext(c).Status(u, input, r.GetOrg(), r.GetName())
if err != nil {
// nolint: lll // ignore long line length due to error message
logrus.Errorf("unable to set commit status for %s/%d: %v", r.GetFullName(), input.GetNumber(), err)
Expand All @@ -258,7 +258,7 @@ func CreateBuild(c *gin.Context) {
c.JSON(http.StatusCreated, input)

// send API call to set the status on the commit
err = source.FromContext(c).Status(u, input, r.GetOrg(), r.GetName())
err = scm.FromContext(c).Status(u, input, r.GetOrg(), r.GetName())
if err != nil {
// nolint: lll // ignore long line length due to error message
logrus.Errorf("unable to set commit status for build %s/%d: %v", r.GetFullName(), input.GetNumber(), err)
Expand Down Expand Up @@ -613,7 +613,7 @@ func GetOrgBuilds(c *gin.Context) {
perPage = util.MaxInt(1, util.MinInt(100, perPage))

// See if the user is an org admin to bypass individual permission checks
perm, err := source.FromContext(c).OrgAccess(u, o)
perm, err := scm.FromContext(c).OrgAccess(u, o)
if err != nil {
logrus.Errorf("unable to get user %s access level for org %s", u.GetName(), o)
}
Expand Down Expand Up @@ -801,7 +801,7 @@ func RestartBuild(c *gin.Context) {
// check if the build event is not pull_request
if !strings.EqualFold(b.GetEvent(), constants.EventPull) {
// send API call to capture list of files changed for the commit
files, err = source.FromContext(c).Changeset(u, r, b.GetCommit())
files, err = scm.FromContext(c).Changeset(u, r, b.GetCommit())
if err != nil {
// nolint: lll // ignore long line length due to error message
retErr := fmt.Errorf("unable to process webhook: failed to get changeset for %s: %w", r.GetFullName(), err)
Expand All @@ -826,7 +826,7 @@ func RestartBuild(c *gin.Context) {
}

// send API call to capture list of files changed for the pull request
files, err = source.FromContext(c).ChangesetPR(u, r, number)
files, err = scm.FromContext(c).ChangesetPR(u, r, number)
if err != nil {
// nolint: lll // ignore long line length due to error message
retErr := fmt.Errorf("unable to process webhook: failed to get changeset for %s: %w", r.GetFullName(), err)
Expand All @@ -838,7 +838,7 @@ func RestartBuild(c *gin.Context) {
}

// send API call to capture the pipeline configuration file
config, err := source.FromContext(c).ConfigBackoff(u, r, b.GetCommit())
config, err := scm.FromContext(c).ConfigBackoff(u, r, b.GetCommit())
if err != nil {
// nolint: lll // ignore long line length due to error message
retErr := fmt.Errorf("unable to get pipeline configuration for %s/%d: %w", r.GetFullName(), b.GetNumber(), err)
Expand Down Expand Up @@ -872,7 +872,7 @@ func RestartBuild(c *gin.Context) {
b.SetStatus(constants.StatusSkipped)

// send API call to set the status on the commit
err = source.FromContext(c).Status(u, b, r.GetOrg(), r.GetName())
err = scm.FromContext(c).Status(u, b, r.GetOrg(), r.GetName())
if err != nil {
logrus.Errorf("unable to set commit status for %s/%d: %v", r.GetFullName(), b.GetNumber(), err)
}
Expand Down Expand Up @@ -904,7 +904,7 @@ func RestartBuild(c *gin.Context) {
c.JSON(http.StatusCreated, b)

// send API call to set the status on the commit
err = source.FromContext(c).Status(u, b, r.GetOrg(), r.GetName())
err = scm.FromContext(c).Status(u, b, r.GetOrg(), r.GetName())
if err != nil {
// nolint: lll // ignore long line length due to error message
logrus.Errorf("unable to set commit status for build %s/%d: %v", r.GetFullName(), b.GetNumber(), err)
Expand Down Expand Up @@ -1067,7 +1067,7 @@ func UpdateBuild(c *gin.Context) {
}

// send API call to set the status on the commit
err = source.FromContext(c).Status(u, b, r.GetOrg(), r.GetName())
err = scm.FromContext(c).Status(u, b, r.GetOrg(), r.GetName())
if err != nil {
// nolint: lll // ignore long line length due to error message
logrus.Errorf("unable to set commit status for build %s/%d: %v", r.GetFullName(), b.GetNumber(), err)
Expand Down
10 changes: 5 additions & 5 deletions api/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/repo"
"github.com/go-vela/server/router/middleware/user"
"github.com/go-vela/server/source"
"github.com/go-vela/server/scm"
"github.com/go-vela/server/util"

"github.com/go-vela/types/library"
Expand Down Expand Up @@ -89,7 +89,7 @@ func CreateDeployment(c *gin.Context) {
}

// send API call to create the deployment
err = source.FromContext(c).CreateDeployment(u, r, input)
err = scm.FromContext(c).CreateDeployment(u, r, input)
if err != nil {
retErr := fmt.Errorf("unable to create new deployment for %s: %w", r.GetFullName(), err)

Expand Down Expand Up @@ -191,7 +191,7 @@ func GetDeployments(c *gin.Context) {
perPage = util.MaxInt(1, util.MinInt(100, perPage))

// send API call to capture the total number of deployments for the repo
t, err := source.FromContext(c).GetDeploymentCount(u, r)
t, err := scm.FromContext(c).GetDeploymentCount(u, r)
if err != nil {
retErr := fmt.Errorf("unable to get deployment count for %s: %w", r.GetFullName(), err)

Expand All @@ -201,7 +201,7 @@ func GetDeployments(c *gin.Context) {
}

// send API call to capture the list of steps for the build
d, err := source.FromContext(c).GetDeploymentList(u, r, page, perPage)
d, err := scm.FromContext(c).GetDeploymentList(u, r, page, perPage)
if err != nil {
retErr := fmt.Errorf("unable to get deployments for %s: %w", r.GetFullName(), err)

Expand Down Expand Up @@ -302,7 +302,7 @@ func GetDeployment(c *gin.Context) {
}

// send API call to capture the deployment
d, err := source.FromContext(c).GetDeployment(u, r, int64(number))
d, err := scm.FromContext(c).GetDeployment(u, r, int64(number))
if err != nil {
retErr := fmt.Errorf("unable to get deployment %s/%d: %w", r.GetFullName(), number, err)

Expand Down
14 changes: 7 additions & 7 deletions api/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (

"github.com/go-vela/server/compiler"
"github.com/go-vela/server/compiler/registry/github"
"github.com/go-vela/server/scm"

"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/repo"
"github.com/go-vela/server/source"
"github.com/go-vela/server/util"

"github.com/go-vela/types"
Expand Down Expand Up @@ -94,7 +94,7 @@ func GetPipeline(c *gin.Context) {
}

// send API call to capture the pipeline configuration file
config, err := source.FromContext(c).ConfigBackoff(u, r, ref)
config, err := scm.FromContext(c).ConfigBackoff(u, r, ref)
if err != nil {
// nolint: lll // ignore long line length due to error message
retErr := fmt.Errorf("unable to get pipeline configuration for %s@%s: %w", r.GetFullName(), ref, err)
Expand Down Expand Up @@ -196,7 +196,7 @@ func GetTemplates(c *gin.Context) {
}

// send API call to capture the pipeline configuration file
config, err := source.FromContext(c).ConfigBackoff(u, r, ref)
config, err := scm.FromContext(c).ConfigBackoff(u, r, ref)
if err != nil {
// nolint: lll // ignore long line length due to error message
retErr := fmt.Errorf("unable to get pipeline configuration for %s@%s: %w", r.GetFullName(), ref, err)
Expand Down Expand Up @@ -309,7 +309,7 @@ func ExpandPipeline(c *gin.Context) {
}

// send API call to capture the pipeline configuration file
config, err := source.FromContext(c).ConfigBackoff(u, r, ref)
config, err := scm.FromContext(c).ConfigBackoff(u, r, ref)
if err != nil {
// nolint: lll // ignore long line length due to error message
retErr := fmt.Errorf("unable to get pipeline configuration for %s@%s: %w", r.GetFullName(), ref, err)
Expand Down Expand Up @@ -440,7 +440,7 @@ func ValidatePipeline(c *gin.Context) {
}

// send API call to capture the pipeline configuration file
config, err := source.FromContext(c).ConfigBackoff(u, r, ref)
config, err := scm.FromContext(c).ConfigBackoff(u, r, ref)
if err != nil {
// nolint: lll // ignore long line length due to error message
retErr := fmt.Errorf("unable to get pipeline configuration for %s@%s: %w", r.GetFullName(), ref, err)
Expand Down Expand Up @@ -579,7 +579,7 @@ func CompilePipeline(c *gin.Context) {
}

// send API call to capture the pipeline configuration file
config, err := source.FromContext(c).ConfigBackoff(u, r, ref)
config, err := scm.FromContext(c).ConfigBackoff(u, r, ref)
if err != nil {
// nolint: lll // ignore long line length due to error message
retErr := fmt.Errorf("unable to get pipeline configuration for %s@%s: %w", r.GetFullName(), ref, err)
Expand Down Expand Up @@ -705,7 +705,7 @@ func setTemplateLinks(c *gin.Context, u *library.User, templates yaml.TemplateSl
}

// retrieve link to template file from github
link, err := source.FromContext(c).GetHTMLURL(u, src.Org, src.Repo, src.Name, src.Ref)
link, err := scm.FromContext(c).GetHTMLURL(u, src.Org, src.Repo, src.Name, src.Ref)
if err != nil {
retErr := fmt.Errorf("unable to get html url for %s/%s/%s/@%s: %w", src.Org, src.Repo, src.Name, src.Ref, err)

Expand Down
18 changes: 9 additions & 9 deletions api/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/repo"
"github.com/go-vela/server/router/middleware/user"
"github.com/go-vela/server/source"
"github.com/go-vela/server/scm"
"github.com/go-vela/server/util"

"github.com/go-vela/types/constants"
Expand Down Expand Up @@ -91,7 +91,7 @@ func CreateRepo(c *gin.Context) {
}

// get repo information from the source
r, err := source.FromContext(c).GetRepo(u, input)
r, err := scm.FromContext(c).GetRepo(u, input)
if err != nil {
retErr := fmt.Errorf("unable to retrieve repo info for %s from source: %w", r.GetFullName(), err)

Expand Down Expand Up @@ -204,7 +204,7 @@ func CreateRepo(c *gin.Context) {

// send API call to create the webhook
if c.Value("webhookvalidation").(bool) {
_, err = source.FromContext(c).Enable(u, r.GetOrg(), r.GetName(), r.GetHash())
_, err = scm.FromContext(c).Enable(u, r.GetOrg(), r.GetName(), r.GetHash())
if err != nil {
retErr := fmt.Errorf("unable to create webhook for %s: %w", r.GetFullName(), err)

Expand Down Expand Up @@ -457,7 +457,7 @@ func GetOrgRepos(c *gin.Context) {
perPage = util.MaxInt(1, util.MinInt(100, perPage))

// See if the user is an org admin to bypass individual permission checks
perm, err := source.FromContext(c).OrgAccess(u, org)
perm, err := scm.FromContext(c).OrgAccess(u, org)
if err != nil {
logrus.Errorf("unable to get user %s access level for org %s", u.GetName(), org)
}
Expand Down Expand Up @@ -780,7 +780,7 @@ func DeleteRepo(c *gin.Context) {
logrus.Infof("Deleting repo %s", r.GetFullName())

// send API call to remove the webhook
err := source.FromContext(c).Disable(u, r.GetOrg(), r.GetName())
err := scm.FromContext(c).Disable(u, r.GetOrg(), r.GetName())
if err != nil {
retErr := fmt.Errorf("unable to delete webhook for %s: %w", r.GetFullName(), err)

Expand Down Expand Up @@ -854,7 +854,7 @@ func RepairRepo(c *gin.Context) {
// capture middleware values
r := repo.Retrieve(c)
u := user.Retrieve(c)
s := source.FromContext(c)
s := scm.FromContext(c)

logrus.Infof("Repairing repo %s", r.GetFullName())

Expand Down Expand Up @@ -1013,7 +1013,7 @@ func SyncRepos(c *gin.Context) {
logrus.Infof("Reading repos for org %s", org)

// See if the user is an org admin to bypass individual permission checks
perm, err := source.FromContext(c).OrgAccess(u, org)
perm, err := scm.FromContext(c).OrgAccess(u, org)
if err != nil {
logrus.Errorf("unable to get user %s access level for org %s", u.GetName(), org)
}
Expand Down Expand Up @@ -1053,7 +1053,7 @@ func SyncRepos(c *gin.Context) {

// iterate through captured repos and check if they are in GitHub
for _, repo := range repos {
_, err := source.FromContext(c).GetRepo(u, repo)
_, err := scm.FromContext(c).GetRepo(u, repo)
// if repo cannot be captured from GitHub, set to inactive in database
if err != nil {
repo.SetActive(false)
Expand Down Expand Up @@ -1115,7 +1115,7 @@ func SyncRepo(c *gin.Context) {
r, _ := database.FromContext(c).GetRepo(org, repo)

// retrieve repo from source code manager service
_, err := source.FromContext(c).GetRepo(u, r)
_, err := scm.FromContext(c).GetRepo(u, r)

// if there is an error retrieving repo, we know it is deleted: sync time
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions api/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"strings"

"github.com/go-vela/server/router/middleware/user"
"github.com/go-vela/server/scm"
"github.com/go-vela/server/secret"
"github.com/go-vela/server/source"
"github.com/go-vela/server/util"

"github.com/go-vela/types/constants"
Expand Down Expand Up @@ -232,7 +232,7 @@ func GetSecrets(c *gin.Context) {
// get list of user's teams if type is shared secret and team is '*'
if t == "shared" && n == "*" {
var err error
teams, err = source.FromContext(c).ListUsersTeamsForOrg(u, o)
teams, err = scm.FromContext(c).ListUsersTeamsForOrg(u, o)
if err != nil {
retErr := fmt.Errorf("unable to get users %s teams for org %s: %v", u.GetName(), o, err)

Expand Down
Loading

0 comments on commit 1bf0240

Please sign in to comment.