Skip to content

Commit b9cdfe0

Browse files
authored
fix: error on update command (#54)
* fix: error on update command * fix: pre * chore: flow
1 parent a9ee085 commit b9cdfe0

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

commands.go

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,39 @@ func init() {
2525
}
2626

2727
func UpdateBranchCmd(command *handlers.Request, args string) error {
28+
const (
29+
mergeText = `
30+
🛠️ I failed to merge %s into your branch, you have to resolve conflicts manually
31+
32+
<details>
33+
<summary>
34+
How to merge branch manually:
35+
</summary>
36+
<pre><code>git checkout %s
37+
git pull origin
38+
git checkout %s
39+
git merge %s
40+
# resolve conflicts
41+
git push origin</code></pre>
42+
43+
</details>
44+
`
45+
)
2846
if err := command.UpdateFromMaster(); err != nil {
2947
logger.Info("command.UpdateFromMaster failed", "error", err)
48+
mergeError := &handlers.MergeError{}
49+
if errors.As(err, &mergeError) {
50+
text := fmt.Sprintf(
51+
mergeText,
52+
mergeError.DestinationBranch,
53+
mergeError.DestinationBranch,
54+
mergeError.SourceBranch,
55+
mergeError.DestinationBranch,
56+
)
57+
58+
return command.LeaveComment(text)
59+
}
60+
3061
return command.LeaveComment("❌ i couldn't update the branch from the destination")
3162
}
3263

@@ -39,7 +70,7 @@ func MergeCmd(command *handlers.Request, args string) error {
3970
return fmt.Errorf("command.Merge returns err: %w", err)
4071
}
4172

42-
if !ok && len(text) > 0 {
73+
if !ok {
4374
return command.LeaveComment(text)
4475
}
4576
return err
@@ -51,7 +82,7 @@ func CheckCmd(command *handlers.Request, args string) error {
5182
return fmt.Errorf("command.IsValid returns err: %w", err)
5283
}
5384

54-
if !ok && len(text) > 0 {
85+
if !ok {
5586
return command.LeaveComment(text)
5687
} else {
5788
return command.LeaveComment("You can merge, LGTM :D")

handlers/merge.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ const (
2020
defaultRemote = "origin"
2121
)
2222

23+
type MergeError struct {
24+
SourceBranch string
25+
DestinationBranch string
26+
}
27+
28+
func (e *MergeError) Error() string {
29+
return "you have to merge your destination branch manually"
30+
}
31+
2332
//nolint:errcheck
2433
func MergeMaster(username, password, repoUrl, branchName, master string) error {
2534

@@ -66,7 +75,13 @@ func MergeMaster(username, password, repoUrl, branchName, master string) error {
6675
logger.Debug("git merge error", "output", output)
6776
if output, err := git.Merge(workingDir, merge.NoFf, merge.Commits(master), merge.M(fmt.Sprintf("✨ merged %s", master))); err != nil {
6877
logger.Debug("git merge --no-ff error", "output", output)
69-
return fmt.Errorf("git merge --no-ff error: %w, output: %s", err, output)
78+
79+
mergeError := &MergeError{
80+
DestinationBranch: master,
81+
SourceBranch: branchName,
82+
}
83+
84+
return fmt.Errorf("git merge --no-ff error: %w, output: %s", mergeError, output)
7085
}
7186
}
7287

0 commit comments

Comments
 (0)