diff --git a/.github/workflows/auto-assign-issue.yml b/.github/workflows/auto-assign-issue.yml index 320174d8c..875432a46 100644 --- a/.github/workflows/auto-assign-issue.yml +++ b/.github/workflows/auto-assign-issue.yml @@ -5,23 +5,23 @@ on: jobs: assign-issue: if: | - contains(github.event.comment.body, '/assign') || contains(github.event.comment.body, '/accept') && + (contains(github.event.comment.body, '/assign') || contains(github.event.comment.body, '/accept')) && !contains(github.event.comment.user.login, 'openim-robot') runs-on: ubuntu-latest permissions: issues: write steps: - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@v7.0.0 - name: Assign the issue run: | - export LETASE_MILESTONES=$(curl 'https://api.github.com/repos/$OWNER/$PEPO/milestones' | jq -r 'last(.[]).title') + export LATEST_MILESTONE=$(curl "https://api.github.com/repos/$OWNER/$REPO/milestones" | jq -r 'last(.[]).title') gh issue edit ${{ github.event.issue.number }} --add-assignee "${{ github.event.comment.user.login }}" gh issue edit ${{ github.event.issue.number }} --add-label "accepted" - gh issue comment $ISSUE --body "@${{ github.event.comment.user.login }} Glad to see you accepted this issue🤲, this issue has been assigned to you. I set the milestones for this issue to [$LETASE_MILESTONES](https://github.com/$OWNER/$PEPO/milestones), We are looking forward to your PR!" + gh issue comment $ISSUE --body "@${{ github.event.comment.user.login }} Glad to see you accepted this issue🤲, this issue has been assigned to you. I set the milestones for this issue to [$LATEST_MILESTONE](https://github.com/$OWNER/$REPO/milestones), We are looking forward to your PR!" - # gh issue edit ${{ github.event.issue.number }} --milestone "$LETASE_MILESTONES" + # gh issue edit ${{ github.event.issue.number }} --milestone "$LATEST_MILESTONE" env: GH_TOKEN: ${{ secrets.BOT_TOKEN }} ISSUE: ${{ github.event.issue.html_url }} diff --git a/.github/workflows/auto-invite-comment.yml b/.github/workflows/auto-invite-comment.yml index dde36eaf1..a4b1f1bf0 100644 --- a/.github/workflows/auto-invite-comment.yml +++ b/.github/workflows/auto-invite-comment.yml @@ -12,7 +12,7 @@ jobs: issues: write steps: - name: Invite user to join OpenIM Community - uses: peter-evans/create-or-update-comment@v4 + uses: peter-evans/create-or-update-comment@v5.0.0 with: token: ${{ secrets.BOT_GITHUB_TOKEN }} issue-number: ${{ github.event.issue.number }} diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index b97036d91..09584ffa1 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -13,7 +13,12 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@v7.0.0 + + - name: Set up Go + uses: actions/setup-go@v6.5.0 + with: + go-version-file: go.mod - name: Run Go Changelog Generator run: | @@ -66,7 +71,7 @@ jobs: rm -f "${{ github.event.release.tag_name }}-changelog.md" - name: Create Pull Request - uses: peter-evans/create-pull-request@v7.0.5 + uses: peter-evans/create-pull-request@v8.1.1 with: token: ${{ secrets.GITHUB_TOKEN }} commit-message: "Update CHANGELOG for release ${{ github.event.release.tag_name }}" diff --git a/.github/workflows/cla-assistant.yml b/.github/workflows/cla-assistant.yml index 7d44b05eb..88c16c8c7 100644 --- a/.github/workflows/cla-assistant.yml +++ b/.github/workflows/cla-assistant.yml @@ -18,7 +18,7 @@ jobs: steps: - name: "CLA Assistant" if: (github.event.comment.body == 'recheck' || github.event.comment.body == 'I have read the CLA Document and I hereby sign the CLA') || github.event_name == 'pull_request_target' - uses: contributor-assistant/github-action@v2.4.0 + uses: contributor-assistant/github-action@v2.6.1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} PERSONAL_ACCESS_TOKEN: ${{ secrets.BOT_TOKEN }} diff --git a/.github/workflows/cleanup-after-milestone-prs-merged.yml b/.github/workflows/cleanup-after-milestone-prs-merged.yml index 8a3e381d6..8d7868de4 100644 --- a/.github/workflows/cleanup-after-milestone-prs-merged.yml +++ b/.github/workflows/cleanup-after-milestone-prs-merged.yml @@ -11,14 +11,13 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4.2.0 + uses: actions/checkout@v7.0.0 - name: Get the PR title and extract PR numbers id: extract_pr_numbers + env: + PR_TITLE: ${{ github.event.pull_request.title }} run: | - # Get the PR title - PR_TITLE="${{ github.event.pull_request.title }}" - echo "PR Title: $PR_TITLE" # Extract PR numbers from the title @@ -57,9 +56,8 @@ jobs: - name: Delete branch after PR close if: steps.extract_pr_numbers.outputs.proceed == 'true' || contains(github.event.pull_request.labels.*.name, 'milestone-merge') + env: + BRANCH_NAME: ${{ github.event.pull_request.head.ref }} run: | - BRANCH_NAME="${{ github.event.pull_request.head.ref }}" echo "Branch to delete: $BRANCH_NAME" git push origin --delete "$BRANCH_NAME" - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index fd871e2b5..340d23614 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -35,11 +35,11 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v7.0.0 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v3 + uses: github/codeql-action/init@v4.36.2 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -50,7 +50,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@v3 + uses: github/codeql-action/autobuild@v4.36.2 # ℹ️ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -64,4 +64,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v3 \ No newline at end of file + uses: github/codeql-action/analyze@v4.36.2 diff --git a/.github/workflows/comment-check.yml b/.github/workflows/comment-check.yml index e994b5259..ec4a1e3ac 100644 --- a/.github/workflows/comment-check.yml +++ b/.github/workflows/comment-check.yml @@ -17,7 +17,7 @@ jobs: EXCLUDE_FILES: "*.md *.txt *.html *.css *.min.js *.mdx" steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v7.0.0 - name: Search for Non-English comments run: | diff --git a/.github/workflows/docker-build-and-release-services-images.yml b/.github/workflows/docker-build-and-release-services-images.yml index 1d085e153..941f83cfa 100644 --- a/.github/workflows/docker-build-and-release-services-images.yml +++ b/.github/workflows/docker-build-and-release-services-images.yml @@ -22,29 +22,29 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v7.0.0 - name: Set up QEMU - uses: docker/setup-qemu-action@v3.3.0 + uses: docker/setup-qemu-action@v4.1.0 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3.8.0 + uses: docker/setup-buildx-action@v4.1.0 - name: Log in to Docker Hub - uses: docker/login-action@v3.3.0 + uses: docker/login-action@v4.2.0 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Log in to GitHub Container Registry - uses: docker/login-action@v3.3.0 + uses: docker/login-action@v4.2.0 with: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - name: Log in to Aliyun Container Registry - uses: docker/login-action@v3.3.0 + uses: docker/login-action@v4.2.0 with: registry: registry.cn-hangzhou.aliyuncs.com username: ${{ secrets.ALIREGISTRY_USERNAME }} diff --git a/.github/workflows/go-build-test.yml b/.github/workflows/go-build-test.yml index 8425293e9..98995ecce 100644 --- a/.github/workflows/go-build-test.yml +++ b/.github/workflows/go-build-test.yml @@ -22,14 +22,14 @@ jobs: strategy: matrix: os: [ubuntu-latest] - go_version: ["1.25.x"] + go_version: ["stable"] steps: - name: Checkout Server repository - uses: actions/checkout@v4 + uses: actions/checkout@v7.0.0 - name: Set up Go ${{ matrix.go_version }} - uses: actions/setup-go@v5 + uses: actions/setup-go@v6.5.0 with: go-version: ${{ matrix.go_version }} @@ -40,7 +40,7 @@ jobs: go mod download - name: Set up infra services - uses: hoverkraft-tech/compose-action@v2.0.1 + uses: hoverkraft-tech/compose-action@v3.0.0 with: compose-file: "./docker-compose.yml" @@ -67,7 +67,7 @@ jobs: mage check - name: Checkout Chat repository - uses: actions/checkout@v4 + uses: actions/checkout@v7.0.0 with: repository: "openimsdk/chat" path: "chat-repo" @@ -188,21 +188,21 @@ jobs: strategy: matrix: os: [ubuntu-latest] - go_version: ["1.25.x"] + go_version: ["stable"] steps: - name: Checkout Server repository - uses: actions/checkout@v4 + uses: actions/checkout@v7.0.0 - name: Checkout SDK repository - uses: actions/checkout@v4 + uses: actions/checkout@v7.0.0 with: repository: "openimsdk/openim-sdk-core" ref: "main" path: ${{ env.SDK_DIR }} - name: Set up Go ${{ matrix.go_version }} - uses: actions/setup-go@v5 + uses: actions/setup-go@v6.5.0 with: go-version: ${{ matrix.go_version }} @@ -237,14 +237,14 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go_version: ["1.25.x"] + go_version: ["stable"] steps: - name: Checkout Repository - uses: actions/checkout@v4 + uses: actions/checkout@v7.0.0 - name: Set up Go ${{ matrix.go_version }} - uses: actions/setup-go@v5 + uses: actions/setup-go@v6.5.0 with: go-version: ${{ matrix.go_version }} diff --git a/.github/workflows/help-comment-issue.yml b/.github/workflows/help-comment-issue.yml index ce8f12b3b..b7f9b5afc 100644 --- a/.github/workflows/help-comment-issue.yml +++ b/.github/workflows/help-comment-issue.yml @@ -26,7 +26,7 @@ jobs: issues: write steps: - name: Add comment - uses: peter-evans/create-or-update-comment@v4 + uses: peter-evans/create-or-update-comment@v5.0.0 with: issue-number: ${{ github.event.issue.number }} token: ${{ secrets.BOT_TOKEN }} diff --git a/.github/workflows/merge-from-milestone.yml b/.github/workflows/merge-from-milestone.yml index a0ec2ac16..23dcf6d16 100644 --- a/.github/workflows/merge-from-milestone.yml +++ b/.github/workflows/merge-from-milestone.yml @@ -40,7 +40,7 @@ jobs: touch ${{ env.TEMP_DIR }}/created_pr_number.txt - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v7.0.0 with: fetch-depth: 0 token: ${{ secrets.BOT_TOKEN }} diff --git a/.github/workflows/publish-docker-image.yml b/.github/workflows/publish-docker-image.yml index 4cd3316dd..db4c1976b 100644 --- a/.github/workflows/publish-docker-image.yml +++ b/.github/workflows/publish-docker-image.yml @@ -14,7 +14,6 @@ on: default: "v3.8.3" env: - GO_VERSION: "1.22" IMAGE_NAME: "openim-server" # IMAGE_NAME: ${{ github.event.repository.name }} DOCKER_BUILDKIT: 1 @@ -25,22 +24,22 @@ jobs: if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.merged == false) }} steps: - name: Checkout main repository - uses: actions/checkout@v4 + uses: actions/checkout@v7.0.0 with: path: main-repo - name: Set up QEMU - uses: docker/setup-qemu-action@v3.3.0 + uses: docker/setup-qemu-action@v4.1.0 - name: Set up Docker Buildx id: buildx - uses: docker/setup-buildx-action@v3 + uses: docker/setup-buildx-action@v4.1.0 with: driver-opts: network=host - name: Extract metadata for Docker id: meta - uses: docker/metadata-action@v5.6.0 + uses: docker/metadata-action@v6.1.0 with: images: | ${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }} @@ -80,7 +79,7 @@ jobs: docker image ls | grep openim - name: Checkout compose repository - uses: actions/checkout@v4 + uses: actions/checkout@v7.0.0 with: repository: "openimsdk/openim-docker" path: "compose-repo" @@ -134,20 +133,20 @@ jobs: # fi - name: Log in to Docker Hub - uses: docker/login-action@v3.3.0 + uses: docker/login-action@v4.2.0 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Log in to GitHub Container Registry - uses: docker/login-action@v3.3.0 + uses: docker/login-action@v4.2.0 with: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - name: Log in to Aliyun Container Registry - uses: docker/login-action@v3.3.0 + uses: docker/login-action@v4.2.0 with: registry: registry.cn-hangzhou.aliyuncs.com username: ${{ secrets.ALIREGISTRY_USERNAME }} diff --git a/.github/workflows/remove-unused-labels.yml b/.github/workflows/remove-unused-labels.yml index ab80b1f96..dd75c0cdf 100644 --- a/.github/workflows/remove-unused-labels.yml +++ b/.github/workflows/remove-unused-labels.yml @@ -11,11 +11,11 @@ jobs: contents: read steps: - name: Checkout Repository - uses: actions/checkout@v4 + uses: actions/checkout@v7.0.0 - name: Fetch All Issues and PRs id: fetch_issues_prs - uses: actions/github-script@v7.0.1 + uses: actions/github-script@v9.0.0 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | @@ -38,7 +38,7 @@ jobs: - name: Fetch All Labels id: fetch_labels - uses: actions/github-script@v7.0.1 + uses: actions/github-script@v9.0.0 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | @@ -52,7 +52,7 @@ jobs: result-encoding: string - name: Remove Unused Labels - uses: actions/github-script@v7.0.1 + uses: actions/github-script@v9.0.0 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | diff --git a/.github/workflows/reopen-issue.yml b/.github/workflows/reopen-issue.yml index 32f838ba4..345f09c87 100644 --- a/.github/workflows/reopen-issue.yml +++ b/.github/workflows/reopen-issue.yml @@ -12,11 +12,11 @@ jobs: steps: - name: Checkout Repository - uses: actions/checkout@v4 + uses: actions/checkout@v7.0.0 - name: Fetch Closed Issues with lifecycle/stale Label id: fetch_issues - uses: actions/github-script@v7 + uses: actions/github-script@v9.0.0 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | @@ -40,7 +40,7 @@ jobs: echo "Issue numbers: ${{ steps.fetch_issues.outputs.result }}" - name: Reopen Issues - uses: actions/github-script@v7 + uses: actions/github-script@v9.0.0 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | @@ -59,7 +59,7 @@ jobs: } - name: Remove lifecycle/stale Label - uses: actions/github-script@v7 + uses: actions/github-script@v9.0.0 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | diff --git a/.github/workflows/update-version-file-on-release.yml b/.github/workflows/update-version-file-on-release.yml index 039ff3d4b..4cad8f55d 100644 --- a/.github/workflows/update-version-file-on-release.yml +++ b/.github/workflows/update-version-file-on-release.yml @@ -12,7 +12,7 @@ jobs: steps: # Step 1: Checkout the original repository's code - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@v7.0.0 with: fetch-depth: 0 # submodules: "recursive" @@ -73,7 +73,7 @@ jobs: # Step 7: Find and Publish Draft Release - name: Find and Publish Draft Release - uses: actions/github-script@v7 + uses: actions/github-script@v9.0.0 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | diff --git a/.github/workflows/user-first-interaction.yml b/.github/workflows/user-first-interaction.yml index 4271702a6..97533a151 100644 --- a/.github/workflows/user-first-interaction.yml +++ b/.github/workflows/user-first-interaction.yml @@ -11,11 +11,11 @@ jobs: check_for_first_interaction: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: actions/first-interaction@v1.3.0 + - uses: actions/checkout@v7.0.0 + - uses: actions/first-interaction@v3.1.0 with: - repo-token: ${{ secrets.BOT_TOKEN }} - pr-message: | + repo_token: ${{ secrets.BOT_TOKEN }} + pr_message: | Hello! Thank you for your contribution. If you are fixing a bug, please reference the issue number in the description. @@ -26,7 +26,7 @@ jobs: Please leave your information in the [✨ discussions](https://github.com/orgs/OpenIMSDK/discussions/426), we expect anyone to join OpenIM developer community. - issue-message: | + issue_message: | Hello! Thank you for filing an issue. If this is a bug report, please include relevant logs to help us debug the problem. diff --git a/Dockerfile b/Dockerfile index 30af8f7ee..c1fceefb5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.25-alpine AS builder +FROM golang:alpine AS builder ARG RELEASE=false ARG COMPRESS=false diff --git a/build/build.sh b/build/build.sh index 354cd3945..e61b228a3 100755 --- a/build/build.sh +++ b/build/build.sh @@ -24,19 +24,13 @@ fi cd "$BASE_DIR/.." || exit 1 split_values() { - printf '%s\n' "$1" | tr ', ' '\n\n' | while IFS= read -r value; do - [[ -n "$value" ]] && printf '%s\n' "$value" - done -} - -print_command() { - printf '%q ' "$@" - printf '\n' + echo "$1" | grep -o '[^, ]\+' } run_or_print() { if [[ "$DRY_RUN" == "true" ]]; then - print_command "$@" + printf '%q ' "$@" + printf '\n' else "$@" fi @@ -44,7 +38,9 @@ run_or_print() { build_local() { echo -e "${CYAN}Building all services...${NO_COLOR}" - RELEASE="$RELEASE" docker compose -f "$COMPOSE_FILE" build + while IFS= read -r service; do + RELEASE="$RELEASE" docker compose -f "$COMPOSE_FILE" build "$service" + done < <(docker compose -f "$COMPOSE_FILE" config --services) echo -e "${CYAN}Tagging compatibility images for Kubernetes...${NO_COLOR}" while IFS= read -r built_image; do diff --git a/build/images/openim-server/Dockerfile b/build/images/openim-server/Dockerfile index e821260a6..6adecf484 100644 --- a/build/images/openim-server/Dockerfile +++ b/build/images/openim-server/Dockerfile @@ -1,8 +1,4 @@ -FROM golang:1.25-alpine AS builder - -ARG CMD_PATH -ARG BINARY_NAME -ARG RELEASE=false +FROM golang:alpine AS builder ENV SERVER_DIR=/openim-server WORKDIR $SERVER_DIR @@ -10,6 +6,10 @@ WORKDIR $SERVER_DIR COPY . . RUN go mod tidy +ARG CMD_PATH +ARG BINARY_NAME +ARG RELEASE=false + RUN if [ "$RELEASE" = "true" ]; then \ go build -trimpath -ldflags "-s -w" -o _output/${BINARY_NAME} ./${CMD_PATH}; \ else \ diff --git a/build/images/openim-server/docker-compose.build.override.yml b/build/images/openim-server/docker-compose.build.override.yml deleted file mode 100644 index 7ef19f988..000000000 --- a/build/images/openim-server/docker-compose.build.override.yml +++ /dev/null @@ -1,72 +0,0 @@ -services: - openim-api: - build: - platforms: - - linux/amd64 - - linux/arm64 - - openim-crontask: - build: - platforms: - - linux/amd64 - - linux/arm64 - - openim-msggateway: - build: - platforms: - - linux/amd64 - - linux/arm64 - - openim-msgtransfer: - build: - platforms: - - linux/amd64 - - linux/arm64 - - openim-push: - build: - platforms: - - linux/amd64 - - linux/arm64 - - openim-rpc-auth: - build: - platforms: - - linux/amd64 - - linux/arm64 - - openim-rpc-conversation: - build: - platforms: - - linux/amd64 - - linux/arm64 - - openim-rpc-friend: - build: - platforms: - - linux/amd64 - - linux/arm64 - - openim-rpc-group: - build: - platforms: - - linux/amd64 - - linux/arm64 - - openim-rpc-msg: - build: - platforms: - - linux/amd64 - - linux/arm64 - - openim-rpc-third: - build: - platforms: - - linux/amd64 - - linux/arm64 - - openim-rpc-user: - build: - platforms: - - linux/amd64 - - linux/arm64 diff --git a/tools/changelog/changelog.go b/tools/changelog/changelog.go index 75d914a27..b76dc6e1d 100644 --- a/tools/changelog/changelog.go +++ b/tools/changelog/changelog.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "errors" "fmt" "io" "net/http" @@ -35,6 +36,10 @@ type ReleaseData struct { Published string `json:"published_at"` } +type GitHubError struct { + Message string `json:"message"` +} + // Method to classify and format release notes. func (g *GitHubRepo) classifyReleaseNotes(body string) map[string][]string { result := map[string][]string{ @@ -49,10 +54,7 @@ func (g *GitHubRepo) classifyReleaseNotes(body string) map[string][]string { // Regular expression to extract PR number and URL (case insensitive) rePR := regexp.MustCompile(`(?i)in (https://github\.com/[^\s]+/pull/(\d+))`) - // Split the body into individual lines. - lines := strings.Split(body, "\n") - - for _, line := range lines { + for line := range strings.SplitSeq(body, "\n") { // Skip lines that contain "deps: Merge" if strings.Contains(strings.ToLower(line), "deps: merge #") { continue @@ -108,7 +110,17 @@ func (g *GitHubRepo) classifyReleaseNotes(body string) map[string][]string { } // Method to generate the final changelog. -func (g *GitHubRepo) generateChangelog(tag, date, htmlURL, body string) string { +func (g *GitHubRepo) generateChangelog(tag, date, htmlURL, body string) (string, error) { + if tag == "" { + return "", errors.New("release tag is empty") + } + if len(date) < 10 { + return "", fmt.Errorf("release published_at is invalid: %q", date) + } + if htmlURL == "" { + return "", errors.New("release html_url is empty") + } + sections := g.classifyReleaseNotes(body) // Convert ISO 8601 date to simpler format (YYYY-MM-DD) @@ -140,7 +152,7 @@ func (g *GitHubRepo) generateChangelog(tag, date, htmlURL, body string) string { changelog += fmt.Sprintf("**Full Changelog**: %s\n", g.FullChangelog) } - return changelog + return changelog, nil } // Method to fetch release data from GitHub API. @@ -165,6 +177,13 @@ func (g *GitHubRepo) fetchReleaseData(version string) (*ReleaseData, error) { if err != nil { return nil, err } + if resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusMultipleChoices { + var githubError GitHubError + if err := json.Unmarshal(body, &githubError); err == nil && githubError.Message != "" { + return nil, fmt.Errorf("github api returned %s: %s", resp.Status, githubError.Message) + } + return nil, fmt.Errorf("github api returned %s", resp.Status) + } var releaseData ReleaseData err = json.Unmarshal(body, &releaseData) @@ -188,11 +207,15 @@ func main() { // Fetch release data (either for latest or specific version) releaseData, err := repo.fetchReleaseData(version) if err != nil { - fmt.Println("Error fetching release data:", err) - return + fmt.Fprintln(os.Stderr, "Error fetching release data:", err) + os.Exit(1) } // Generate and print the formatted changelog - changelog := repo.generateChangelog(releaseData.TagName, releaseData.Published, releaseData.HtmlUrl, releaseData.Body) + changelog, err := repo.generateChangelog(releaseData.TagName, releaseData.Published, releaseData.HtmlUrl, releaseData.Body) + if err != nil { + fmt.Fprintln(os.Stderr, "Error generating changelog:", err) + os.Exit(1) + } fmt.Println(changelog) }