Skip to content

Adding, renaming and removing resources

Every resource of an organization, e.g. a repository, a team or a webhook, is declared in otterdog/<org>.jsonnet. To add, rename or remove one, change its declaration and propose the change with a pull request, see Workflow for changes.

TL;DR

Add

Declare the resource with its orgs.new… function at its place, with only the values that differ from the default configuration.

Auto-merge, except for secrets and private repositories.

Adding a resource

Rename

Change the name of a repository or the URL of a webhook, and list the previous one in aliases. Otherwise, the resource is deleted and created again.

Auto-merge with aliases.

Renaming a resource

Remove

Delete its declaration: once merged, otterdog deletes the resource on GitHub, a repository with all its content.

Always merged by an admin.

Removing a resource

How otterdog recognizes a resource

otterdog matches the resources of the configuration with the ones on GitHub by their identifier, e.g. the name of a repository or the URL of a webhook. Whether the identifier matches decides what the change does:

ConfigurationValidation GitHub

newRepo('website')~ modifywebsite: only what differs changes

newRepo('new-tool')+ createno new-tool yet

newRepo('docs') with aliases: ['documentation']~ renamedocumentation: renamed to docs

old-lib removed by the pull request- deleteold-lib: deleted

A resource is only deleted when a pull request removes it from the configuration. The identifier of each resource:

Resource Identifier
Repository name, and its aliases
Webhook of the organization or of a repository url, and its aliases
Team, organization role, custom property, code security configuration name
Secret (Actions, Dependabot, Codespaces), variable, environment, ruleset name
Actions policy name
Branch protection rule pattern
IdP group connected to a team (team_sync) id

Adding a resource

Declare the resource with the function of the default configuration at its place in the configuration:

The rules of a ruleset have their own functions too, they are the values of the keys of the ruleset:

Each function and its properties are documented in the Reference, e.g. Repository. The new resource inherits all the values of the default configuration: only declare the ones that differ, see Inherited and explicit values.

For example, to add a repository new-repo next to an existing one:

 orgs.newOrg('my-project', 'my-org') {
   _repositories+:: [
     orgs.newRepo('existing-repo') {
       description: "My first repository",
     },
+    orgs.newRepo('new-repo') {
+      description: "My second repository",
+      allow_merge_commit: false,
+      dependabot_alerts_enabled: false,
+    },
   ],
 }

Try it in the Playground

The Playground of the dashboard shows the resulting resource with the values of the default configuration, and can propose the change as a pull request, see Prepare your change.

A repository defined by the default configuration

Use orgs.extendRepo('<name>') instead of orgs.newRepo('<name>') to change a repository that the default configuration already defines: orgs.newRepo would reset the values it customized.

Some properties are only used when the repository is created, e.g. template_repository or forked_repository to create it from a template or as a fork, see Common repository patterns.

What it means for the merge

Auto-merge, once approved

A public repository, a team, a variable, a ruleset, an environment, or a webhook without secret.

An admin applies the secret

A secret (Actions, Dependabot or Codespaces), or a webhook with a secret: an admin merges the pull request and applies the secret.

An admin checks the costs

A private repository, or one with a GitHub Actions cache above the free limit.

See Changes that prevent the auto-merge.

Renaming a resource

Changing the identifier of a resource, e.g. the name of a repository, does not rename it: otterdog no longer finds the resource with its previous identifier on GitHub, deletes it and creates a new one. For a repository or a webhook, aliases keeps it:

Without aliases

newRepo('new-name')+ createno new-name: a new, empty repository

no old-name any more- deleteold-name: deleted with its issues, pull requests and wiki

With aliases: ['old-name']

newRepo('new-name') with aliases: ['old-name']~ renameold-name: renamed, with all its content

Never rename a repository without aliases

The validation of the pull request shows the repository as removed and added again. Such a pull request cannot be auto-merged, but once merged, the repository is deleted with its content, which otterdog cannot restore.

Repositories and webhooks: aliases

List the previous identifiers of the resource in aliases:

orgs.newRepo('new-name') {
  aliases: ['old-name'],
  description: "My repository",
},

The validation of the pull request then shows a renaming instead of a deletion, which can be auto-merged:

~ repository[name="new-name"] {
~   name = "old-name" -> "new-name"
~ }
orgs.newOrgWebhook('https://ci.example.org/hooks/github') {
  aliases: ['https://ci.example.org/github-webhook/'],
  events+: [
    "push",
  ],
},

The existing webhook keeps its deliveries and settings, only its URL changes. A webhook with a secret is applied by an admin, see Change the URL of a webhook.

Once the change is applied, aliases is no longer needed. You can keep it to record the previous identifiers of the resource.

The other resources

The other resources are deleted and created again when their identifier changes. Their settings come from the configuration, but what otterdog does not manage is lost, e.g. the deployment history of an environment. As the pull request removes a resource, an admin merges it.

Removing a resource

Delete the declaration of the resource from the configuration. For example, to remove a webhook of the organization:

 orgs.newOrg('my-project', 'my-org') {
   webhooks+: [
-    orgs.newOrgWebhook('https://ci.example.org/github-webhook/') {
-      events+: [
-        "pull_request",
-        "push",
-      ],
-    },
   ],
 }

Pull request

Removes the declaration of the resource.

Validation

Shows the resource as removed, no auto-merge.

Admin

Reviews and merges the pull request.

Deletion

otterdog deletes the resource on GitHub.

A pull request that removes a resource is never auto-merged: a member of the admin teams reviews and merges it. Only the resources that the pull request removes from the configuration are deleted, the other resources of GitHub are left untouched.

Removing a repository deletes it, with its content

Its issues, pull requests and wiki are deleted, otterdog cannot restore them. Prefer archiving the repository with archived: true, see Renaming, archiving and deleting.

A resource inherited from the default configuration

A resource that the default configuration declares is not in your configuration: to remove it, replace the inherited list instead of extending it, i.e. rulesets: [...] instead of rulesets+: [...], see Extending or replacing values.