Skip to content

Commit

Permalink
feat(dependabot): add target-branch configuration (#3537)
Browse files Browse the repository at this point in the history
Adding missing target-branch option to the dependabot configuration.

---
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
  • Loading branch information
abdsahin committed Apr 26, 2024
1 parent 9eb1e59 commit b1af086
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/api/github.md
Original file line number Diff line number Diff line change
Expand Up @@ -4838,6 +4838,7 @@ const dependabotOptions: github.DependabotOptions = { ... }
| <code><a href="#projen.github.DependabotOptions.property.registries">registries</a></code> | <code>{[ key: string ]: <a href="#projen.github.DependabotRegistry">DependabotRegistry</a>}</code> | Map of package registries to use. |
| <code><a href="#projen.github.DependabotOptions.property.reviewers">reviewers</a></code> | <code>string[]</code> | Specify individual reviewers or teams of reviewers for all pull requests raised for a package manager. |
| <code><a href="#projen.github.DependabotOptions.property.scheduleInterval">scheduleInterval</a></code> | <code><a href="#projen.github.DependabotScheduleInterval">DependabotScheduleInterval</a></code> | How often to check for new versions and raise pull requests. |
| <code><a href="#projen.github.DependabotOptions.property.targetBranch">targetBranch</a></code> | <code>string</code> | https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file#target-branch You can configure the target branch for raising pull requests for version updates against. |
| <code><a href="#projen.github.DependabotOptions.property.versioningStrategy">versioningStrategy</a></code> | <code><a href="#projen.github.VersioningStrategy">VersioningStrategy</a></code> | The strategy to use when edits manifest and lock files. |

---
Expand Down Expand Up @@ -4986,6 +4987,18 @@ How often to check for new versions and raise pull requests.

---

##### `targetBranch`<sup>Optional</sup> <a name="targetBranch" id="projen.github.DependabotOptions.property.targetBranch"></a>

```typescript
public readonly targetBranch: string;
```

- *Type:* string

https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file#target-branch You can configure the target branch for raising pull requests for version updates against.

---

##### `versioningStrategy`<sup>Optional</sup> <a name="versioningStrategy" id="projen.github.DependabotOptions.property.versioningStrategy"></a>

```typescript
Expand Down
7 changes: 7 additions & 0 deletions src/github/dependabot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ export interface DependabotOptions {
* @default []
*/
readonly groups?: { [name: string]: DependabotGroup };

/**
* https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file#target-branch
* You can configure the target branch for raising pull requests for version updates against
*/
readonly targetBranch?: string;
}

/**
Expand Down Expand Up @@ -390,6 +396,7 @@ export class Dependabot extends Component {
options.openPullRequestsLimit !== undefined
? options.openPullRequestsLimit
: undefined,
"target-branch": options.targetBranch,
},
],
};
Expand Down
31 changes: 31 additions & 0 deletions test/github/__snapshots__/dependabot.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions test/github/dependabot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,36 @@ describe("dependabot", () => {
expect(dependabot).toContain("dependency-name: projen");
});
});

describe("target branch", () => {
test("empty target branch", () => {
const project = createProject();

new Dependabot(project.github!, {});

const snapshot = synthSnapshot(project);
const dependabot = snapshot[".github/dependabot.yml"];
expect(dependabot).toBeDefined();
expect(dependabot).toMatchSnapshot();
expect(dependabot).not.toContain("target-branch4");
});

test("develop as the target branch", () => {
const project = createProject();

const targetBranch = "develop";

new Dependabot(project.github!, {
targetBranch: targetBranch,
});

const snapshot = synthSnapshot(project);
const dependabot = snapshot[".github/dependabot.yml"];
expect(dependabot).toBeDefined();
expect(dependabot).toMatchSnapshot();
expect(dependabot).toContain(`target-branch: ${targetBranch}`);
});
});
});

type ProjectOptions = Omit<
Expand Down

0 comments on commit b1af086

Please sign in to comment.