Skip to content

Commit e79f251

Browse files
authored
fix unlock for gcp (#110)
* print error if unlock failed * report more error messages * merge main into branch
1 parent 4bdc731 commit e79f251

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

pkg/digger/digger.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,17 +263,23 @@ func (d DiggerExecutor) Apply(prNumber int) {
263263
d.prManager.PublishComment(prNumber, comment)
264264
if err == nil {
265265
_, err := d.lock.Unlock(d.LockId(), prNumber)
266-
fmt.Errorf("error unlocking project: %v", err)
266+
if err != nil {
267+
fmt.Errorf("error unlocking project: %v", err)
268+
}
267269
} else {
270+
268271
d.prManager.PublishComment(prNumber, "Error during applying. Project lock will persist")
269272
}
270273
}
271274

272275
}
273276

274277
func (d DiggerExecutor) Unlock(prNumber int) {
275-
d.lock.ForceUnlock(d.LockId(), prNumber)
276-
278+
err := d.lock.ForceUnlock(d.LockId(), prNumber)
279+
if err != nil {
280+
fmt.Printf("%v\n", err)
281+
os.Exit(1)
282+
}
277283
}
278284

279285
func (d DiggerExecutor) Lock(prNumber int) bool {

pkg/utils/locking.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type Lock interface {
3636
type ProjectLock interface {
3737
Lock(lockId string, prNumber int) (bool, error)
3838
Unlock(lockId string, prNumber int) (bool, error)
39-
ForceUnlock(lockId string, prNumber int)
39+
ForceUnlock(lockId string, prNumber int) error
4040
}
4141

4242
func (projectLock *ProjectLockImpl) Lock(lockId string, prNumber int) (bool, error) {
@@ -104,18 +104,26 @@ func (projectLock *ProjectLockImpl) Unlock(lockId string, prNumber int) (bool, e
104104
return false, nil
105105
}
106106

107-
func (projectLock *ProjectLockImpl) ForceUnlock(lockId string, prNumber int) {
107+
func (projectLock *ProjectLockImpl) ForceUnlock(lockId string, prNumber int) error {
108108
fmt.Printf("ForceUnlock %s\n", lockId)
109-
lock, _ := projectLock.InternalLock.GetLock(lockId)
109+
lock, err := projectLock.InternalLock.GetLock(lockId)
110+
if err != nil {
111+
return err
112+
}
110113
if lock != nil {
111-
lockReleased, _ := projectLock.InternalLock.Unlock(lockId)
114+
lockReleased, err := projectLock.InternalLock.Unlock(lockId)
115+
if err != nil {
116+
return err
117+
}
112118

113119
if lockReleased {
114120
comment := "Project unlocked (" + projectLock.projectId() + ")."
115121
projectLock.PrManager.PublishComment(prNumber, comment)
116122
println("Project unlocked")
117123
}
124+
return nil
118125
}
126+
return nil
119127
}
120128

121129
func (projectLock *ProjectLockImpl) projectId() string {

0 commit comments

Comments
 (0)