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

package main

import (
	"errors"
	"fmt"
	"path/filepath"

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

func doCleanNamespace(r *gitpb.Repo) error {
	// check for GO repos
	gowork := env.Get("gopath")
	// todo: detect if using go.work file
	newpath, err := filepath.Rel(gowork, r.FullPath)
	if err != nil {
		log.Info("cleanNamespace got err", newpath, err)
		// check for other stuff. use the URLs
		return err
	}
	if newpath == r.Namespace {
		// namespace was already set right
		return nil
	}
	r.Namespace = newpath
	err = errors.New("namepace changed")
	s := fmt.Sprintf("old(%s), new(%s)", r.Namespace, newpath)
	return errors.Join(errors.New(s), err)
}

// checks to see if the r.Namespace seems right
func doVerifyNamespace() (string, error) {
	fixed := me.forge.RunOnRepos(me.forge.Repos, doCleanNamespace)
	if fixed.Len() != 0 {
		fixed = fixed.SortActual()
		footer := me.forge.PrintDefaultTB(fixed)
		me.forge.Repos.SaveVerbose()
		return "changed namespaces: " + footer, nil
	}
	return "no namespaces changed", nil
}