summaryrefslogtreecommitdiff
path: root/doVerify.go
blob: 647f8084da8142c7604bf804168f9ef4cb0da62a (plain)
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
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0

package main

import (
	"path/filepath"

	"go.wit.com/lib/protobuf/gitpb"
	"go.wit.com/log"
)

func doVerify() (string, error) {
	var s string = "doVerify()"
	var err error

	if argv.Verify.Stats != nil {
		s, err = doStats()
	}

	if argv.Verify.Namespace != nil {
		s, err = doVerifyNamespace()
	}

	return s, err
}

func cleanNamespace(r *gitpb.Repo) string {
	// check for GO repos
	gowork := me.forge.Config.ReposDir
	// todo: detect if using go.work file
	newpath, err := filepath.Rel(gowork, r.FullPath)
	log.Info("cleanNamespace()", newpath, gowork, "is gowork. fullpath:", r.FullPath)
	if err == nil {
		log.Info("cleanNamespace returned", newpath)
		// relative path to gosrc or gowork is the namespace
		return newpath
	}
	log.Info("cleanNamespace got err", newpath, err)
	// check for other stuff. use the URLs
	return ""
}

// checks to see if the r.Namespace seems right
func doVerifyNamespace() (string, error) {
	var s string = "doVerifyNamespace()"
	var err error
	var changed bool
	for r := range me.forge.Repos.IterAll() {
		newpath := cleanNamespace(r)
		if newpath == "" {
			log.Info("didn't work", r.Namespace, "to", newpath)
			// didn't work
		} else if newpath != r.Namespace {
			log.Info("Changed", r.FullPath, "to", r.Namespace)
			r.Namespace = newpath
			continue
		} else {
			log.Info("Not Changed", r.Namespace, "to", newpath)
		}
		log.Info("not sure about", r.Namespace)
	}

	if changed {
		me.forge.Repos.SaveVerbose()
	}

	return s, err
}