-
Notifications
You must be signed in to change notification settings - Fork 0
[Actions] Create Encrich PR Action #64
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
Changes from all commits
42f17ba
868676e
13154b3
9e4f8e5
9ab4c4f
0666db5
1946e3c
101a7bd
9511dfe
0d1b144
a2ce255
b975c36
5bb1388
b95fc06
ec9bf51
36f1993
750f49d
c79a527
90e8c9c
9ef6537
a76c0b2
5263a26
255beb9
c7f0531
aafacb4
fd094be
26c534b
5f24a30
4f87db6
18955a8
f02af8c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| FROM golang:1.24-alpine AS builder | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # Copy go mod and sum files | ||
| COPY go.mod go.sum ./ | ||
|
|
||
| # Download dependencies | ||
| RUN go mod download | ||
|
|
||
| # Copy source code | ||
| COPY . . | ||
|
|
||
| # Build the binary | ||
| RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main . | ||
|
|
||
| # Final stage - minimal image | ||
| FROM alpine:latest | ||
|
|
||
| # Install ca-certificates for HTTPS requests | ||
| RUN apk --no-cache add ca-certificates | ||
|
|
||
| # Create a non-root user | ||
| RUN addgroup -g 1001 -S appgroup && \ | ||
| adduser -u 1001 -S appuser -G appgroup | ||
|
|
||
| # Set working directory | ||
| WORKDIR /app | ||
|
|
||
| # Copy the binary from builder stage | ||
| COPY --from=builder /app/main . | ||
|
|
||
| # Set ownership and permissions | ||
| RUN chown appuser:appgroup /app/main && \ | ||
| chmod +x /app/main | ||
|
|
||
| # Switch to non-root user | ||
| USER appuser | ||
|
|
||
| # Run the binary | ||
| ENTRYPOINT ["/app/main"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| name: 'Enrich Pull Request' | ||
| description: "Enrich's the pull request with information from your project management system." | ||
| inputs: | ||
| repository: | ||
| description: 'The repository name' | ||
| required: true | ||
| type: string | ||
| pullRequestNumber: | ||
| description: 'The pull request number' | ||
| required: true | ||
| type: string | ||
| branch: | ||
| description: 'The branch name' | ||
| required: true | ||
| type: string | ||
| token: | ||
| description: 'GitHub token' | ||
| required: true | ||
| customFormatting: | ||
| description: "User defined custom formatting rules for specific words." | ||
| required: false | ||
| default: "" | ||
| strategy: | ||
| type: string | ||
| description: 'Which formatting strategy should be used' | ||
| required: false | ||
| default: 'branch-name' | ||
| jiraURL: | ||
| type: string | ||
| description: 'URL to your jira instance' | ||
| required: false | ||
| default: '' | ||
| jiraEmail: | ||
| type: string | ||
| description: 'Jira auth email' | ||
| required: false | ||
| default: '' | ||
| jiraToken: | ||
| type: string | ||
| description: 'Jira auth token' | ||
| required: false | ||
| default: '' | ||
| jiraEnableSyncLabel: | ||
| type: boolean | ||
| description: 'Use a sync label' | ||
| required: false | ||
| default: true | ||
| jiraEnableSyncDescription: | ||
| type: boolean | ||
| description: 'Sync Jira description to PR description' | ||
| required: false | ||
| default: true | ||
| jiraSyncLabelName: | ||
| type: string | ||
| description: 'Name of the sync label' | ||
| required: false | ||
| default: 'jira-sync-complete' | ||
| runs: | ||
| using: 'docker' | ||
| image: 'docker://ghcr.io/encoredigitalgroup/gh-action-enrich-pull-request:latest' | ||
| env: | ||
| GH_TOKEN: ${{ inputs.token }} | ||
| GH_REPOSITORY: ${{ inputs.repository }} | ||
| PR_NUMBER: ${{ inputs.pullRequestNumber }} | ||
| BRANCH_NAME: ${{ inputs.branch }} | ||
| ENABLE_EXPERIMENTS: ${{ inputs.enableExperiments }} | ||
| OPT_FMT_WORDS: ${{ inputs.customFormatting }} | ||
| OPT_FMT_STRATEGY: ${{ inputs.strategy }} | ||
| OPT_JIRA_URL: ${{ inputs.jiraURL }} | ||
| OPT_JIRA_EMAIL: ${{ inputs.jiraEmail }} | ||
| OPT_JIRA_TOKEN: ${{ inputs.jiraToken }} | ||
| OPT_ENABLE_JIRA_SYNC_LABEL: ${{ inputs.jiraEnableSyncLabel }} | ||
| OPT_JIRA_SYNC_LABEL_NAME: ${{ inputs.jiraSyncLabelName }} | ||
| OPT_ENABLE_JIRA_SYNC_DESCRIPTION: ${{ inputs.jiraEnableSyncDescription }} |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,65 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| package branchname | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "fmt" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "os" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "regexp" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/EncoreDigitalGroup/golib/logger" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/EncoreDigitalGroup/ci-workflows/actions/github/enrichPullRequest/support/github" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var regexWithIssueType = regexp.MustCompile(`^(epic|feature|bugfix|hotfix)/([A-Z]+-[0-9]+)-(.+)$`) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var regexWithoutIssueType = regexp.MustCompile(`^([A-Z]+-[0-9]+)-(.+)$`) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var pullRequestTitle string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func Format(gh github.GitHub) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| branchName, err := gh.GetBranchName() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger.Error(err.Error()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| os.Exit(1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if !gh.BranchNameMatchesPRTitle(branchName) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| formattedTitle := formatTitle(gh, branchName) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| gh.UpdatePRTitle(formattedTitle) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
onairmarc marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func GetIssueKeyFromBranchName(branchName string) (string, error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if matches := regexWithIssueType.FindStringSubmatch(branchName); matches != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return matches[2], nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else if matches := regexWithoutIssueType.FindStringSubmatch(branchName); matches != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return matches[1], nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fmt.Println("Title does not match expected format") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger.Info(pullRequestTitle) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return "", nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
onairmarc marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func GetIssueNameFromBranchName(branchName string) (string, error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if matches := regexWithIssueType.FindStringSubmatch(branchName); matches != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return matches[3], nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else if matches := regexWithoutIssueType.FindStringSubmatch(branchName); matches != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return matches[2], nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fmt.Println("Title does not match expected format") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger.Info(pullRequestTitle) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return "", nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+42
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do the same for the issue name extraction. We need an error when we can't extract the human-readable name; otherwise we still go ahead and format func GetIssueNameFromBranchName(branchName string) (string, error) {
- if matches := regexWithIssueType.FindStringSubmatch(branchName); matches != nil {
- return matches[3], nil
- } else if matches := regexWithoutIssueType.FindStringSubmatch(branchName); matches != nil {
- return matches[2], nil
- } else {
- fmt.Println("Title does not match expected format")
- logger.Info(pullRequestTitle)
- return "", nil
- }
+ if matches := regexWithIssueType.FindStringSubmatch(branchName); matches != nil {
+ return matches[3], nil
+ }
+ if matches := regexWithoutIssueType.FindStringSubmatch(branchName); matches != nil {
+ return matches[2], nil
+ }
+ return "", fmt.Errorf("branch name %q does not match expected format", branchName)
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func formatTitle(gh github.GitHub, branchName string) string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| issueKey, err := GetIssueKeyFromBranchName(branchName) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| issueName, err := GetIssueNameFromBranchName(branchName) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fmt.Println("Title does not match expected format") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger.Error(err.Error()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return pullRequestTitle | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return gh.ApplyFormatting(issueKey, issueName) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+54
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Because both calls reuse the same -func formatTitle(gh github.GitHub, branchName string) string {
- issueKey, err := GetIssueKeyFromBranchName(branchName)
- issueName, err := GetIssueNameFromBranchName(branchName)
-
- if err != nil {
- fmt.Println("Title does not match expected format")
- logger.Error(err.Error())
- return pullRequestTitle
- }
-
- return gh.ApplyFormatting(issueKey, issueName)
-}
+func formatTitle(gh github.GitHub, branchName string) (string, error) {
+ issueKey, err := GetIssueKeyFromBranchName(branchName)
+ if err != nil {
+ return "", err
+ }
+
+ issueName, err := GetIssueNameFromBranchName(branchName)
+ if err != nil {
+ return "", err
+ }
+
+ if issueKey == "" || issueName == "" {
+ return "", fmt.Errorf("branch name %q does not contain both issue key and name", branchName)
+ }
+
+ return gh.ApplyFormatting(issueKey, issueName), nil
+}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package drivers | ||
|
|
||
| const BranchName = "branch-name" | ||
| const Jira = "jira" | ||
|
|
||
| func Validate(driver string) bool { | ||
| validDrivers := []string{ | ||
| BranchName, | ||
| Jira, | ||
| } | ||
|
|
||
| for _, validDriver := range validDrivers { | ||
| if driver == validDriver { | ||
| return true | ||
| } | ||
| } | ||
|
|
||
| return false | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.