Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions pkg/digger/digger.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,17 +263,23 @@ func (d DiggerExecutor) Apply(prNumber int) {
d.prManager.PublishComment(prNumber, comment)
if err == nil {
_, err := d.lock.Unlock(d.LockId(), prNumber)
fmt.Errorf("error unlocking project: %v", err)
if err != nil {
fmt.Errorf("error unlocking project: %v", err)
}
} else {

d.prManager.PublishComment(prNumber, "Error during applying. Project lock will persist")
}
}

}

func (d DiggerExecutor) Unlock(prNumber int) {
d.lock.ForceUnlock(d.LockId(), prNumber)

err := d.lock.ForceUnlock(d.LockId(), prNumber)
if err != nil {
fmt.Printf("%v\n", err)
os.Exit(1)
}
}

func (d DiggerExecutor) Lock(prNumber int) bool {
Expand Down
16 changes: 12 additions & 4 deletions pkg/utils/locking.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Lock interface {
type ProjectLock interface {
Lock(lockId string, prNumber int) (bool, error)
Unlock(lockId string, prNumber int) (bool, error)
ForceUnlock(lockId string, prNumber int)
ForceUnlock(lockId string, prNumber int) error
}

func (projectLock *ProjectLockImpl) Lock(lockId string, prNumber int) (bool, error) {
Expand Down Expand Up @@ -104,18 +104,26 @@ func (projectLock *ProjectLockImpl) Unlock(lockId string, prNumber int) (bool, e
return false, nil
}

func (projectLock *ProjectLockImpl) ForceUnlock(lockId string, prNumber int) {
func (projectLock *ProjectLockImpl) ForceUnlock(lockId string, prNumber int) error {
fmt.Printf("ForceUnlock %s\n", lockId)
lock, _ := projectLock.InternalLock.GetLock(lockId)
lock, err := projectLock.InternalLock.GetLock(lockId)
if err != nil {
return err
}
if lock != nil {
lockReleased, _ := projectLock.InternalLock.Unlock(lockId)
lockReleased, err := projectLock.InternalLock.Unlock(lockId)
if err != nil {
return err
}

if lockReleased {
comment := "Project unlocked (" + projectLock.projectId() + ")."
projectLock.PrManager.PublishComment(prNumber, comment)
println("Project unlocked")
}
return nil
}
return nil
}

func (projectLock *ProjectLockImpl) projectId() string {
Expand Down