• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2020 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package git
16
17import (
18	"bufio"
19	"os"
20	"path"
21)
22
23type repoLister struct {
24}
25
26func NewRepoLister() ProjectLister {
27	var rl repoLister
28	return &rl
29}
30
31func (rl repoLister) List(codebasePath string) ([]string, error) {
32	projectList := []string{".repo"}
33	listPath := path.Join(codebasePath, ".repo/project.list")
34	listFile, err := os.Open(listPath)
35	if err != nil {
36		return projectList, err
37	}
38	defer listFile.Close()
39	scanner := bufio.NewScanner(listFile)
40	for scanner.Scan() {
41		line := scanner.Text()
42		if line != "" {
43			projectList = append(projectList, line)
44		}
45	}
46	return projectList, err
47}
48