1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
  | 
package main
import (
	"strings"
	"go.wit.com/lib/protobuf/gitpb"
	"go.wit.com/lib/protobuf/httppb"
	"go.wit.com/log"
)
func handleRepos(pb *gitpb.Repos, route string) error {
	log.Info("GOT PATCHES ROUTE", route, "with # patches =", pb.Len())
	if strings.HasPrefix(route, "/patches/old") {
	} else if strings.HasPrefix(route, "/patches/new") {
		log.Info("add new patches")
	} else {
		log.Info("unknown route", route)
	}
	return nil
}
// returns a repo PB with just the master and devel branch versions
// is just this information so it keeps things small when it's sent over the wire
func getCurrentRepoVersions(namespace string) *gitpb.Repo {
	newrepo := new(gitpb.Repo)
	newrepo.Namespace = namespace
	found := me.forge.Repos.FindByNamespace(namespace)
	if found == nil {
		// todo: clone repo here
		return newrepo
	}
	newrepo.URL = found.URL
	return newrepo
}
func pullRequest(pb *gitpb.Repos, reqPB *httppb.HttpRequest) *gitpb.Repos {
	versionsPB := gitpb.NewRepos()
	for repo := range pb.IterAll() {
		found := getCurrentRepoVersions(repo.Namespace)
		versionsPB.Append(found)
	}
	return versionsPB
}
func addRequest(pb *gitpb.Repos, reqPB *httppb.HttpRequest) *gitpb.Repos {
	newReposPB := gitpb.NewRepos()
	for repo := range pb.IterAll() {
		if found := me.forge.Repos.FindByNamespace(repo.Namespace); found != nil {
			// already know about this namespace
			continue
		} else {
			newReposPB.Append(found)
		}
		/*
			newrepo := new(gitpb.Repo)
			newrepo.Namespace = repo.Namespace
			newrepo.URL = repo.URL
		*/
	}
	return newReposPB
}
func checkRequest(pb *gitpb.Repos, reqPB *httppb.HttpRequest) *gitpb.Repos {
	checkPB := gitpb.NewRepos()
	for repo := range pb.IterAll() {
		// found := me.forge.PrepareCheckRepo(repo.Namespace)
		found := me.forge.Repos.FindByNamespace(repo.Namespace)
		if found == nil {
			if me.missing == nil {
				continue
			}
			// new missing repo
			me.missing.AppendByNamespace(repo)
			continue
		}
		if found.GetURL() != repo.GetURL() {
			log.Infof("'%s' url %s mismatch %s\n", found.FullPath, found.GetURL(), repo.GetURL())
		}
		checkPB.Append(found)
	}
	saveMissing()
	return checkPB
}
func updateURLs(pb *gitpb.Repos, reqPB *httppb.HttpRequest) *gitpb.Repos {
	checkPB := gitpb.NewRepos()
	for repo := range pb.IterAll() {
		found := me.forge.Repos.FindByNamespace(repo.Namespace)
		if found == nil {
			log.Infof("found == nil namespace=%s\n", repo.Namespace)
			continue
		}
		if found.GetURL() != repo.GetURL() {
			log.Infof("'%s' url %s mismatch %s\n", found.FullPath, found.GetURL(), repo.GetURL())
			cmd := []string{"git", "remote", "set-url", "origin", repo.GetURL()}
			found.RunVerbose(cmd)
		} else {
			// log.Infof("'%s' url %s == %s\n", found.FullPath, found.GetURL(), repo.GetURL())
		}
		checkPB.Append(found)
	}
	return checkPB
}
  |