From 11fde2ee29a99c61d12f396f6953d51809686e1b Mon Sep 17 00:00:00 2001 From: chemotaxis Date: Wed, 27 Apr 2022 01:43:35 -0400 Subject: [PATCH] Restructured switch statement As much as I like keeping statements as flat as possible, this not-as-flat revision just seems easier to read. --- pkg/cmd/issue/lock/lock.go | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/pkg/cmd/issue/lock/lock.go b/pkg/cmd/issue/lock/lock.go index 47b0c8bbc..0af2c45bb 100644 --- a/pkg/cmd/issue/lock/lock.go +++ b/pkg/cmd/issue/lock/lock.go @@ -203,24 +203,27 @@ func padlock(state string, opts *LockOptions) error { successMsg := fmt.Sprintf("%s %s\n", cs.SuccessIconWithColor(cs.Green), status(state, issuePr, opts)) - switch { - case state == Lock && !issuePr.Locked: - err = lockLockable(httpClient, baseRepo, issuePr, opts) + switch state { + case Lock: + if !issuePr.Locked { + err = lockLockable(httpClient, baseRepo, issuePr, opts) + } else { + var relocked bool + relocked, err = relockLockable(httpClient, baseRepo, issuePr, opts) - case state == Lock && issuePr.Locked: - relocked, errRelock := relockLockable(httpClient, baseRepo, issuePr, opts) - err = errRelock - if !relocked { - successMsg = fmt.Sprintf("%s #%d already locked%s. Nothing changed.\n", - parent.FullName, issuePr.Number, reason(issuePr.ActiveLockReason)) + if !relocked { + successMsg = fmt.Sprintf("%s #%d already locked%s. Nothing changed.\n", + parent.FullName, issuePr.Number, reason(issuePr.ActiveLockReason)) + } } - case state == Unlock && issuePr.Locked: - err = unlockLockable(httpClient, baseRepo, issuePr, opts) - - case state == Unlock && !issuePr.Locked: - successMsg = fmt.Sprintf("%s #%d already unlocked. Nothing changed.\n", - parent.FullName, issuePr.Number) + case Unlock: + if issuePr.Locked { + err = unlockLockable(httpClient, baseRepo, issuePr, opts) + } else { + successMsg = fmt.Sprintf("%s #%d already unlocked. Nothing changed.\n", + parent.FullName, issuePr.Number) + } } if err != nil {