diff --git a/.dockerignore b/.dockerignore index f2729d3..b3d19f5 100644 --- a/.dockerignore +++ b/.dockerignore @@ -19,3 +19,4 @@ deployments/.env #ignore docker compose file deployments/docker-compose.yaml .DS_Store +.env diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..a1c35c1 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,49 @@ +name: Release + +on: + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: $GITHUB_ACTOR + password: "${{ secrets.GITHUB_TOKEN }}" + - name: Generate a container image + run: | + version=$(cat VERSION) + docker build . -t ghcr.io/${USERNAME_OR_ORG}/github-updates:${version} + docker push ghcr.io/${USERNAME_OR_ORG}/github-updates:${version} + shell: bash + env: + USERNAME_OR_ORG: "${{ github.repository_owner }}" + - name: Increment the pom version + run: | + current_version=$(cat VERSION) + if [[ "$current_version" =~ v([0-9]+)\.([0-9]+) ]]; then + major="${BASH_REMATCH[1]}" + minor="${BASH_REMATCH[2]}" + else + echo "Invalid version format. Expected format: v." + exit 1 + fi + minor=$((minor + 1)) + new_version="v${major}.${minor}" + echo "$new_version" > VERSION + shell: bash + - name: Create Pull Request with new PRs + uses: peter-evans/create-pull-request@v3 + with: + token: "${{ secrets.GITHUB_TOKEN }}" + branch-suffix: timestamp + title: Increment version after release + labels: auto-version-increment + signoff: true + delete-branch: false + commit-message: Auto increment version after release diff --git a/.gitignore b/.gitignore index ef5983b..11b1ff8 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ assets/generated-data/*.json # Ignore .env file deployments/.env .DS_Store +.env diff --git a/Dockerfile b/Dockerfile index 9827d76..3aaea3b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,7 +23,6 @@ RUN make WORKDIR /appbin RUN cp /app/github-updates /appbin/ -RUN rm -r /app ENV PATH=${PATH}:/appbin diff --git a/README.md b/README.md index 6dc549b..b0b21ea 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ global: name: "Hyperledger Labs" github: "hyperledger-labs" scrape-duration-days: 7 + max-records: 0 # to list everything, otherwise consider the maximum number of records in the summary # Set this to true and specify input/output files external-template: enabled: false diff --git a/cmd/main.go b/cmd/main.go index 6461cbb..0dd2c23 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -78,6 +78,7 @@ func main() { generateExternalPR( config.PullRequests.PRExternalTemplate, externalPRList, + config.GlobalConfiguration.MaxRecords, ) if err != nil { log.Fatalf("Failed to generate the report: %v, with template: %v. Error is: %v", @@ -107,6 +108,7 @@ func main() { generateExternalRelease( config.Releases.ReleaseExternalTemplate, externalReleaseList, + config.GlobalConfiguration.MaxRecords, ) if err != nil { log.Fatalf("Failed to generate the report: %v, with template: %v. Error is: %v", @@ -136,6 +138,7 @@ func main() { generateExternalIssue( config.Issues.IssueExternalTemplate, externalIssueList, + config.GlobalConfiguration.MaxRecords, ) if err != nil { log.Fatalf("Failed to generate the report: %v, with template: %v. Error is: %v", @@ -237,6 +240,7 @@ func getExternalReports(config configs.Configuration, func generateExternalPR( externalTemplate configs.ElementExternalTemplate, values []configs.ExternalPRDetails, + maxRecords int, ) error { if len(values) == 0 { log.Println("External template file generation is not requested") @@ -256,12 +260,13 @@ func generateExternalPR( } // store the trending info in summary file - return generateTopFile(recentPRs(values), externalTemplate) + return generateTopFile(recentPRs(values, maxRecords), externalTemplate) } func generateExternalIssue( externalTemplate configs.ElementExternalTemplate, values []configs.ExternalIssueDetails, + maxRecords int, ) error { if len(values) == 0 { log.Println("External template file generation is not requested") @@ -281,12 +286,13 @@ func generateExternalIssue( } // store the trending info in summary file - return generateTopFile(recentIssues(values), externalTemplate) + return generateTopFile(recentIssues(values, maxRecords), externalTemplate) } func generateExternalRelease( externalTemplate configs.ElementExternalTemplate, values []configs.ExternalReleaseDetails, + maxRecords int, ) error { if len(values) == 0 { log.Println("External template file generation is not requested") @@ -306,7 +312,7 @@ func generateExternalRelease( } // store the trending info in summary file - return generateTopFile(recentReleases(values), externalTemplate) + return generateTopFile(recentReleases(values, maxRecords), externalTemplate) } func generateExternalFile( @@ -318,7 +324,7 @@ func generateExternalFile( var err error outputFileName := filename + filepath.Ext(externalTemplate.Input) outputPath := path.Join(externalTemplate.Output, org) - err = os.MkdirAll(outputPath, 755) + err = os.MkdirAll(outputPath, 0755) if err != nil { return err } @@ -482,7 +488,7 @@ func getExpectedPullRequests( return expectedPrs, false } -func recentPRs(prs []configs.ExternalPRDetails) []github.PullRequest { +func recentPRs(prs []configs.ExternalPRDetails, maxRecords int) []github.PullRequest { // get the list of all PRs from across repositories var allPRs []github.PullRequest for _, pr := range prs { @@ -496,10 +502,13 @@ func recentPRs(prs []configs.ExternalPRDetails) []github.PullRequest { // return the top n items // n is 5 for now - return allPRs[:5] + if maxRecords == 0 { + return allPRs + } + return allPRs[:min(len(allPRs), 5)] } -func recentIssues(issues []configs.ExternalIssueDetails) []github.Issue { +func recentIssues(issues []configs.ExternalIssueDetails, maxRecords int) []github.Issue { // get the list of all PRs from across repositories var allIssues []github.Issue for _, issue := range issues { @@ -513,10 +522,13 @@ func recentIssues(issues []configs.ExternalIssueDetails) []github.Issue { // return the top n items // n is 5 for now - return allIssues[:5] + if maxRecords == 0 { + return allIssues + } + return allIssues[:min(len(allIssues), 5)] } -func recentReleases(releases []configs.ExternalReleaseDetails) []github.RepositoryRelease { +func recentReleases(releases []configs.ExternalReleaseDetails, maxRecords int) []github.RepositoryRelease { // get the list of all PRs from across repositories var allReleases []github.RepositoryRelease for _, release := range releases { @@ -530,5 +542,15 @@ func recentReleases(releases []configs.ExternalReleaseDetails) []github.Reposito // return the top n items // n is 5 for now - return allReleases[:5] + if maxRecords == 0 { + return allReleases + } + return allReleases[:min(len(allReleases), maxRecords)] +} + +func min(a, b int) int { + if a < b { + return a + } + return b } diff --git a/internal/pkg/client/ghclient.go b/internal/pkg/client/ghclient.go index 49d341e..7e10fa3 100644 --- a/internal/pkg/client/ghclient.go +++ b/internal/pkg/client/ghclient.go @@ -249,13 +249,15 @@ func (c Client) IssueWithLabels(org string, repos []string, issueLabels []string } for _, issue := range issues { - publishedDate := issue.GetCreatedAt() - startDate := time.Now().AddDate(0, 0, dayDiff) - log.Println("publishedDate", publishedDate, "start date", startDate, " if condition", publishedDate.Before(startDate)) - - if publishedDate.Before(startDate) { - issueDateReached = true - break + if dayDiff != 0 { + publishedDate := issue.GetCreatedAt() + startDate := time.Now().AddDate(0, 0, dayDiff) + log.Println("publishedDate", publishedDate, "start date", startDate, " if condition", publishedDate.Before(startDate)) + + if publishedDate.Before(startDate) { + issueDateReached = true + break + } } //check if the issue contains the desired labels or not @@ -287,7 +289,8 @@ func (c Client) IssueWithLabels(org string, repos []string, issueLabels []string return issueList, nil } -/** +/* +* Utility function to check if the issue contains at least one of the desired labels */ func doesIssueContainLabels(issue *github.Issue, allowedLabels []string) bool { diff --git a/internal/pkg/configs/configuration.go b/internal/pkg/configs/configuration.go index 57e100d..9b50843 100644 --- a/internal/pkg/configs/configuration.go +++ b/internal/pkg/configs/configuration.go @@ -65,6 +65,7 @@ type ElementExternalTemplate struct { type GlobalConfiguration struct { Organizations []Organization `yaml:"organizations"` DaysCount int `yaml:"scrape-duration-days"` + MaxRecords int `yaml:"max-records"` ExternalTemplate ExternalTemplate `yaml:"external-template"` RepoClass string `yaml:"scrape-repo-class"` }