Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdafydd committed Apr 9, 2020
1 parent df357bd commit e6b2629
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
8 changes: 7 additions & 1 deletion server/events/project_locker.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,15 @@ func (p *DefaultProjectLocker) TryLock(log *logging.SimpleLogger, pull models.Pu
return nil, err
}
if !lockAttempt.LockAcquired && lockAttempt.CurrLock.Pull.Num != pull.Num {
pullRefChr := "#"
if pull.BaseRepo.VCSHost.Type == models.AzureDevops {
pullRefChr = "!"
}
failureMsg := fmt.Sprintf(
"This project is currently locked by an unapplied plan from pull #%d. To continue, delete the lock from #%d or apply that plan and merge the pull request.\n\nOnce the lock is released, comment `atlantis plan` here to re-plan.",
"This project is currently locked by an unapplied plan from pull %s%d. To continue, delete the lock from %s%d or apply that plan and merge the pull request.\n\nOnce the lock is released, comment `atlantis plan` here to re-plan.",
pullRefChr,
lockAttempt.CurrLock.Pull.Num,
pullRefChr,
lockAttempt.CurrLock.Pull.Num)
return &TryLockResponse{
LockAcquired: false,
Expand Down
37 changes: 37 additions & 0 deletions server/events/project_locker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,43 @@ func TestDefaultProjectLocker_TryLockWhenLocked(t *testing.T) {
}, res)
}

func TestDefaultProjectLocker_TryLockWhenLockedAzureAzureDevops(t *testing.T) {
mockLocker := mocks.NewMockLocker()
locker := events.DefaultProjectLocker{
Locker: mockLocker,
}
expProject := models.Project{}
expWorkspace := "default"
expPull := models.PullRequest{
BaseRepo: models.Repo{
VCSHost: models.VCSHost{
Type: models.AzureDevops,
},
},
}
expUser := models.User{}

lockingPull := models.PullRequest{
Num: 2,
}
When(mockLocker.TryLock(expProject, expWorkspace, expPull, expUser)).ThenReturn(
locking.TryLockResponse{
LockAcquired: false,
CurrLock: models.ProjectLock{
Pull: lockingPull,
},
LockKey: "",
},
nil,
)
res, err := locker.TryLock(logging.NewNoopLogger(), expPull, expUser, expWorkspace, expProject)
Ok(t, err)
Equals(t, &events.TryLockResponse{
LockAcquired: false,
LockFailureReason: "This project is currently locked by an unapplied plan from pull !2. To continue, delete the lock from !2 or apply that plan and merge the pull request.\n\nOnce the lock is released, comment `atlantis plan` here to re-plan.",
}, res)
}

func TestDefaultProjectLocker_TryLockWhenLockedSamePull(t *testing.T) {
RegisterMockTestingT(t)
mockLocker := mocks.NewMockLocker()
Expand Down

0 comments on commit e6b2629

Please sign in to comment.