-
Notifications
You must be signed in to change notification settings - Fork 360
Add custom properties #2512
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
base: main
Are you sure you want to change the base?
Add custom properties #2512
Changes from all commits
c1f10ba
13f9cb6
f69e388
e001fce
0dadec7
43a88b9
a9b0499
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 |
|---|---|---|
|
|
@@ -353,6 +353,7 @@ private-non-synced = false | |
| #### Bots | ||
|
|
||
| Here are the available bots that can be added to the `bots` array: | ||
|
|
||
| - `datadog`: installs a GitHub App used by DataDog. Used for [CI Visibility](https://www.datadoghq.com/product/ci-cd-monitoring/). It has read access to organization members, and repository | ||
| actions, administration, checks, code scanning alerts, commit statuses, contents, | ||
| deployments, issues, pull requests, secret scanning alerts and secrets. | ||
|
|
@@ -527,7 +528,25 @@ branches = ["develop", "staging"] | |
| # No branch or tag patterns specified - any branch or tag can deploy | ||
| ``` | ||
|
|
||
| ### Repository custom properties | ||
|
|
||
| [Repository custom properties] are values set on a repository to opt it into org-wide tooling. The property must first be defined at the organization level. | ||
|
|
||
| Only boolean values are supported. | ||
|
|
||
| [Repository custom properties]: https://docs.github.com/en/organizations/managing-organization-settings/managing-custom-properties-for-repositories-in-your-organization | ||
|
|
||
| ```toml | ||
| # Repository custom properties (optional) | ||
| [custom-properties] | ||
| # Set a property name to a boolean value | ||
| crabwatch = true | ||
|
Member
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. The property values on GitHub are strings, and the code currently converts bools to a string via its
Contributor
Author
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. That's a fair point. The reason I went with bool is that @marcoieni suggested it earlier. TOML supports it natively, and the conversion to string happens on the Rust side.
Member
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. Yeah, I was wrong on this. The fact that the property crabwatch can be only |
||
| ``` | ||
|
|
||
| Properties set on GitHub but not declared here are left unchanged. | ||
|
|
||
| ### Crates.io crate management | ||
|
|
||
| Configure properties of crates.io crates that are deployed using Trusted Publishing from the given repository. | ||
|
|
||
| ```toml | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,3 +11,6 @@ pattern = "main" | |
| ci-checks = ["CI"] | ||
| required-approvals = 0 | ||
|
|
||
| [custom-properties] | ||
| crabwatch = "true" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -746,3 +746,15 @@ pub(crate) struct BranchPolicy { | |
| fn default_branch_policy_type() -> String { | ||
| "branch".to_string() | ||
| } | ||
|
|
||
| /// A GitHub repository custom property. Values are strings even for booleans. | ||
| #[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] | ||
| pub(crate) struct CustomPropertyValue { | ||
| pub(crate) property_name: String, | ||
| pub(crate) value: Option<String>, | ||
|
Contributor
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. Right now we are modelling propertie values as optional string fields, but actually what we get here in the API response will depend on specifics of custom property settings:
As an example, when we set the property type as gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2026-03-10" \
/repos/dotanuki-labs/testbed/properties/values
[
{
"property_name": "Category",
"value": [
"DevOps"
]
}
]
Perhaps we don't need to support all types of custom properties to get started, but we must clarify that we support only text-field like properties for now |
||
| } | ||
|
|
||
| #[derive(Debug, serde::Serialize)] | ||
| pub(crate) struct SetCustomPropertiesRequest { | ||
| pub(crate) properties: Vec<CustomPropertyValue>, | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,8 +4,8 @@ use std::collections::HashSet; | |
|
|
||
| use crate::sync::github::api::url::GitHubUrl; | ||
| use crate::sync::github::api::{ | ||
| GitHubApiRead, GithubRead, HttpClient, Repo, RepoPermission, RepoSettings, Ruleset, RulesetOp, | ||
| Team, TeamPrivacy, TeamRole, allow_not_found, | ||
| CustomPropertyValue, GitHubApiRead, GithubRead, HttpClient, Repo, RepoPermission, RepoSettings, | ||
| Ruleset, RulesetOp, SetCustomPropertiesRequest, Team, TeamPrivacy, TeamRole, allow_not_found, | ||
| }; | ||
| use crate::sync::utils::ResponseExt; | ||
|
|
||
|
|
@@ -696,4 +696,27 @@ impl GitHubWrite { | |
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| /// Set a custom property value on a repository | ||
| pub(crate) async fn set_custom_property( | ||
| &self, | ||
| org: &str, | ||
| repo: &str, | ||
| property: &CustomPropertyValue, | ||
| ) -> anyhow::Result<()> { | ||
| debug!( | ||
| "Setting custom property '{}' on '{}/{}'", | ||
| property.property_name, org, repo | ||
| ); | ||
| if !self.dry_run { | ||
| // REST API: PATCH /repos/{owner}/{repo}/properties/values | ||
|
Comment on lines
+711
to
+712
Contributor
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. Since custom properties must be pre-defined at org-level to be applied, I think we should capture whether we are able to apply the custom property in the dry-run |
||
| // https://docs.github.com/en/rest/repos/custom-properties#create-or-update-custom-property-values-for-a-repository | ||
| let url = GitHubUrl::repos(org, repo, "properties/values")?; | ||
| let body = SetCustomPropertiesRequest { | ||
| properties: vec![property.clone()], | ||
| }; | ||
| self.client.send(Method::PATCH, &url, &body).await?; | ||
| } | ||
| Ok(()) | ||
| } | ||
| } | ||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check my comment on custom property types, we should elaborate better here