Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LFS Detection Feature #2

Merged
merged 1 commit into from
Jul 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"bufio"
"bytes"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -68,7 +69,7 @@ var (
Use: "gh pma",
Short: Description,
Long: Description,
Version: "0.0.7",
Version: "0.0.8",
SilenceUsage: true,
SilenceErrors: true,
RunE: Process,
Expand All @@ -94,6 +95,9 @@ type apiResponse struct {
Message string
Rate rateResponse
}
type file struct {
Content string
}
type environments struct {
Environments []environment
Total_Count int
Expand Down Expand Up @@ -136,6 +140,7 @@ type repository struct {
Secrets secrets
Variables variables
Environments environments
LFS file
}
type organization struct {
Login string
Expand Down Expand Up @@ -876,6 +881,22 @@ func GetRepositoryStatistics(client api.RESTClient, repoToProcess repository) {
repoToProcess.Environments = envResponse
}

// get LFS definition file
var fileResponse file
_ = client.Get(
fmt.Sprintf(
"repos/%s/contents/.gitattributes",
repoToProcess.NameWithOwner,
),
&fileResponse,
)
Debug(fmt.Sprintf(
"Contents of .gitattributes from %s: %v",
repoToProcess.NameWithOwner,
fileResponse,
))
repoToProcess.LFS = fileResponse

// find if repo exists in target
targetIdx := slices.IndexFunc(TargetRepositories, func(r repository) bool {
return r.Name == repoToProcess.Name
Expand Down Expand Up @@ -1102,7 +1123,18 @@ func ProcessIssues(client api.RESTClient, targetOrg string, reposToProcess []rep
issueTemplate += "## Items From Source\n"
issueTemplate += "- Variables: `%+v`\n"
issueTemplate += "- Secrets: `%+v`\n"
issueTemplate += "- Environments: `%+v`\n"
issueTemplate += "- Environments: `%+v`\n\n"
issueTemplate += "## LFS Detection\n"
issueTemplate += "Only accounts for HEAD branch.\n\n"
decodedLFS, _ := base64.StdEncoding.DecodeString(repository.LFS.Content)
if strings.Contains(string(decodedLFS), "filter=lfs") {
issueTemplate += "Validate the paths referenced in `.gitattributes`:\n"
issueTemplate += "```\n"
issueTemplate += string(decodedLFS)
issueTemplate += "```\n"
} else {
issueTemplate += "No LFS declaration detected in `.gitattributes`\n"
}
issueBody := fmt.Sprintf(
issueTemplate,
repository.Owner,
Expand Down