bug_actions.go

 1package bug
 2
 3import (
 4	"github.com/pkg/errors"
 5
 6	"github.com/MichaelMure/git-bug/entity"
 7	"github.com/MichaelMure/git-bug/entity/dag"
 8	"github.com/MichaelMure/git-bug/identity"
 9	"github.com/MichaelMure/git-bug/repository"
10)
11
12// Fetch retrieve updates from a remote
13// This does not change the local bugs state
14func Fetch(repo repository.Repo, remote string) (string, error) {
15	return dag.Fetch(def, repo, remote)
16}
17
18// Push update a remote with the local changes
19func Push(repo repository.Repo, remote string) (string, error) {
20	return dag.Push(def, repo, remote)
21}
22
23// Pull will do a Fetch + MergeAll
24// This function will return an error if a merge fail
25func Pull(repo repository.ClockedRepo, remote string, author identity.Interface) error {
26	_, err := Fetch(repo, remote)
27	if err != nil {
28		return err
29	}
30
31	for merge := range MergeAll(repo, remote, author) {
32		if merge.Err != nil {
33			return merge.Err
34		}
35		if merge.Status == entity.MergeStatusInvalid {
36			return errors.Errorf("merge failure: %s", merge.Reason)
37		}
38	}
39
40	return nil
41}
42
43// MergeAll will merge all the available remote bug
44// Note: an author is necessary for the case where a merge commit is created, as this commit will
45// have an author and may be signed if a signing key is available.
46func MergeAll(repo repository.ClockedRepo, remote string, author identity.Interface) <-chan entity.MergeResult {
47	// no caching for the merge, we load everything from git even if that means multiple
48	// copy of the same entity in memory. The cache layer will intercept the results to
49	// invalidate entities if necessary.
50	identityResolver := identity.NewSimpleResolver(repo)
51
52	return dag.MergeAll(def, repo, identityResolver, remote, author)
53}
54
55// RemoveBug will remove a local bug from its entity.Id
56func RemoveBug(repo repository.ClockedRepo, id entity.Id) error {
57	return dag.Remove(def, repo, id)
58}