72 lines
2.2 KiB
Go
72 lines
2.2 KiB
Go
// Copyright 2019 Drone IO, Inc.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package trigger
|
|
|
|
// import (
|
|
// "context"
|
|
// "regexp"
|
|
// "strconv"
|
|
|
|
// "github.com/drone/drone/core"
|
|
// "github.com/drone/go-scm/scm"
|
|
// )
|
|
|
|
// func listChanges(client *scm.Client, repo *core.Repository, build *core.Build) ([]string, error) {
|
|
// switch build.Event {
|
|
// case core.EventPullRequest:
|
|
// return listChangesPullRequest(client, repo, build)
|
|
// case core.EventPush:
|
|
// return listChangesPush(client, repo, build)
|
|
// default:
|
|
// return nil, nil
|
|
// }
|
|
// }
|
|
|
|
// func listChangesPullRequest(client *scm.Client, repo *core.Repository, build *core.Build) ([]string, error) {
|
|
// var paths []string
|
|
// pr, err := parsePullRequest(build.Ref)
|
|
// if err != nil {
|
|
// return nil, err
|
|
// }
|
|
// change, _, err := client.PullRequests.ListChanges(context.Background(), repo.Slug, pr, scm.ListOptions{})
|
|
// if err == nil {
|
|
// for _, file := range change {
|
|
// paths = append(paths, file.Path)
|
|
// }
|
|
// }
|
|
// return paths, err
|
|
// }
|
|
|
|
// func listChangesPush(client *scm.Client, repo *core.Repository, build *core.Build) ([]string, error) {
|
|
// var paths []string
|
|
// // TODO (bradrydzewski) some tag hooks provide the tag but do
|
|
// // not provide the sha, in which case we should use the ref
|
|
// // instead of the sha.
|
|
// change, _, err := client.Git.ListChanges(context.Background(), repo.Slug, build.After, scm.ListOptions{})
|
|
// if err == nil {
|
|
// for _, file := range change {
|
|
// paths = append(paths, file.Path)
|
|
// }
|
|
// }
|
|
// return paths, err
|
|
// }
|
|
|
|
// func parsePullRequest(ref string) (int, error) {
|
|
// return strconv.Atoi(
|
|
// pre.FindString(ref),
|
|
// )
|
|
// }
|
|
|
|
// var pre = regexp.MustCompile("\\d+")
|