Skip to content

Commit

Permalink
Merge pull request #82 from laszlocph/pr-source-branch
Browse files Browse the repository at this point in the history
Pr source branch
  • Loading branch information
laszlocph authored Oct 24, 2019
2 parents 272a48f + 3c8e95f commit e691068
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
23 changes: 17 additions & 6 deletions cncd/pipeline/pipeline/frontend/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,26 @@ func (m *Metadata) EnvironDrone() map[string]string {
// * DRONE_YAML_VERIFIED
// * DRONE_YAML_VERIFIED
var (
owner string
name string
owner string
name string
sourceBranch string
targetBranch string

parts = strings.Split(m.Repo.Name, "/")
repoParts = strings.Split(m.Repo.Name, "/")
branchParts = strings.Split(m.Curr.Commit.Refspec, ":")
)
if len(parts) == 2 {
owner = strings.Split(m.Repo.Name, "/")[0]
name = strings.Split(m.Repo.Name, "/")[1]
if len(repoParts) == 2 {
owner = repoParts[0]
name = repoParts[1]
} else {
name = m.Repo.Name
}

if len(branchParts) == 2 {
sourceBranch = branchParts[0]
targetBranch = branchParts[1]
}

params := map[string]string{
"CI": "drone",
"DRONE": "true",
Expand Down Expand Up @@ -205,6 +214,8 @@ func (m *Metadata) EnvironDrone() map[string]string {
"DRONE_JOB_NUMBER": fmt.Sprintf("%d", m.Job.Number),
"DRONE_JOB_STARTED": fmt.Sprintf("%d", m.Curr.Started), // ISSUE: no job started
"DRONE_BRANCH": m.Curr.Commit.Branch,
"DRONE_SOURCE_BRANCH": sourceBranch,
"DRONE_TARGET_BRANCH": targetBranch,
"DRONE_COMMIT": m.Curr.Commit.Sha,
"DRONE_VERSION": m.Sys.Version,
"DRONE_DEPLOY_TO": m.Curr.Target,
Expand Down
2 changes: 2 additions & 0 deletions docs/usage/pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,8 @@ This is the reference list of all environment variables available to your build
| `DRONE_JOB_STARTED` | job started |
| `DRONE_JOB_FINISHED` | job finished |
| `DRONE_BRANCH` | commit branch |
| `DRONE_TARGET_BRANCH` | The target branch of a Pull Request |
| `DRONE_SOURCE_BRANCH` | The source branch of a Pull Request |
| `DRONE_COMMIT` | commit sha |
| `DRONE_TAG` | commit tag |
| `DRONE_PULL_REQUEST` | pull request number |
Expand Down

0 comments on commit e691068

Please sign in to comment.