• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

levibostian / new-deployment-tool / 14242840486

03 Apr 2025 12:22PM UTC coverage: 73.517% (+0.4%) from 73.132%
14242840486

Pull #48

github

web-flow
Merge d7324c618 into f105879dd
Pull Request #48: fix git hooks

110 of 123 branches covered (89.43%)

Branch coverage included in aggregate %.

316 of 423 new or added lines in 15 files covered. (74.7%)

11 existing lines in 4 files now uncovered.

745 of 1040 relevant lines covered (71.63%)

10.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

29.27
/lib/github-actions.ts
1
import { DetermineNextReleaseStepConfig } from "./steps/determine-next-release.ts"
2
import * as log from "./log.ts"
1✔
3
import * as githubActions from "@actions/core"
1✔
4

5
export interface GitHubActions {
6
  getNameOfCurrentBranch(): string
7
  getDetermineNextReleaseStepConfig(): DetermineNextReleaseStepConfig | undefined
8
  getSimulatedMergeType(): "merge" | "rebase" | "squash"
9
  getEventThatTriggeredThisRun(): "push" | "pull_request" | unknown
10
  isRunningInPullRequest(): Promise<{ baseBranch: string; targetBranch: string; prTitle: string; prDescription: string } | undefined>
11
  setOutput({ key, value }: { key: string; value: string }): void
12
}
13

14
export class GitHubActionsImpl implements GitHubActions {
1✔
15
  getNameOfCurrentBranch(): string {
×
NEW
16
    const githubRef = Deno.env.get("GITHUB_REF")!
×
NEW
17
    log.debug(`GITHUB_REF: ${githubRef}`)
×
18

19
    // if the ref starts with "refs/pull/", then it's a pull request.
20
    // the tool is only compatible with branch names that start with "refs/heads/".
21
    // We need a different way to get the branch name.
NEW
22
    if (githubRef.startsWith("refs/pull/")) {
×
NEW
23
      const githubHeadRef = Deno.env.get("GITHUB_HEAD_REF")!
×
NEW
24
      log.debug(`GITHUB_HEAD_REF: ${githubHeadRef}`)
×
NEW
25
      return githubHeadRef
×
UNCOV
26
    }
×
27

NEW
28
    return githubRef.replace("refs/heads/", "")
×
29
  }
×
30

31
  getDetermineNextReleaseStepConfig(): DetermineNextReleaseStepConfig | undefined {
1✔
32
    const githubActionInputKey = "analyze_commits_config"
5✔
33

34
    const determineNextReleaseStepConfig = this.getInput(githubActionInputKey)
5✔
35
    if (!determineNextReleaseStepConfig) {
5✔
36
      return undefined
6✔
37
    }
6✔
38

39
    try {
8✔
40
      // Because every property in the config is optional, if JSON.parse results in an object that is not a DetermineNextReleaseStepConfig, it's ok.
41
      return JSON.parse(determineNextReleaseStepConfig)
8✔
42
    } catch (error) {
5✔
43
      log.error(`When trying to parse the GitHub Actions input value for ${githubActionInputKey}, I encountered an error: ${error}`)
7✔
44
      log.error(`The value I tried to parse was: ${determineNextReleaseStepConfig}`)
7✔
45

46
      throw new Error()
7✔
47
    }
7✔
48
  }
5✔
49

NEW
50
  getSimulatedMergeType(): "merge" | "rebase" | "squash" {
×
NEW
51
    const githubActionInputKey = "simulated_merge_type"
×
52

NEW
53
    const simulateMergeType = this.getInput(githubActionInputKey)
×
54
    if (!simulateMergeType) {
×
NEW
55
      return "merge"
×
56
    }
×
57

NEW
58
    if (simulateMergeType !== "merge" && simulateMergeType !== "rebase" && simulateMergeType !== "squash") {
×
NEW
59
      log.error(
×
NEW
60
        `The value for the GitHub Actions input ${githubActionInputKey} is invalid. The value must be either "merge", "rebase", or "squash". The value provided was: ${simulateMergeType}`,
×
61
      )
62

NEW
63
      throw new Error()
×
64
    }
×
65

NEW
66
    return simulateMergeType
×
67
  }
×
68

NEW
69
  getEventThatTriggeredThisRun(): "push" | "pull_request" | string {
×
NEW
70
    const eventName = Deno.env.get("GITHUB_EVENT_NAME")
×
71

72
    switch (eventName) {
×
73
      case "push":
×
NEW
74
        return "push"
×
75
      case "pull_request":
×
NEW
76
        return "pull_request"
×
77
      default:
×
NEW
78
        return eventName || "unknown"
×
79
    }
×
80
  }
×
81

NEW
82
  async isRunningInPullRequest(): Promise<{ baseBranch: string; targetBranch: string; prTitle: string; prDescription: string } | undefined> {
×
NEW
83
    const githubEventName = Deno.env.get("GITHUB_EVENT_NAME")
×
84
    if (githubEventName !== "pull_request") {
×
NEW
85
      return undefined
×
86
    }
×
87

88
    // object reference: https://docs.github.com/en/webhooks/webhook-events-and-payloads?actionType=opened#pull_request
NEW
89
    const pullRequestContext = await this.getFullRunContext()! // we can force since we know we are in a pull request event
×
90

NEW
91
    const eventData = pullRequestContext.pull_request
×
92

93
    return {
×
UNCOV
94
      baseBranch: eventData.head.ref,
×
95
      targetBranch: eventData.base.ref,
×
96
      prTitle: eventData.title,
×
NEW
97
      prDescription: eventData.body || "", // github body can be null, we want a string.
×
NEW
98
    }
×
UNCOV
99
  }
×
100

NEW
101
  setOutput({ key, value }: { key: string; value: string }): void {
×
NEW
102
    githubActions.setOutput(key, value)
×
UNCOV
103
  }
×
104

105
  private async getFullRunContext(): Promise<any | undefined> {
×
NEW
106
    const eventPath = Deno.env.get("GITHUB_EVENT_PATH")
×
107
    if (eventPath) {
×
NEW
108
      const fileContents = new TextDecoder("utf-8").decode(Deno.readFileSync(eventPath))
×
NEW
109
      return JSON.parse(fileContents)
×
110
    }
×
111
  }
×
112

113
  private getInput(key: string): string {
1✔
114
    return githubActions.getInput(key)
5✔
115
  }
5✔
116
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc