Add a REST API endpoint for getting project configuration
To start, only expose the inheritable booleans stored in the project config, and only to users who can see refs/meta/config. Change-Id: I299a5317fb641e84b899f8240764c4902a34c72a
This commit is contained in:
		| @@ -408,6 +408,41 @@ link:#repository-statistics-info[RepositoryStatisticsInfo] entity. | |||||||
|   } |   } | ||||||
| ---- | ---- | ||||||
|  |  | ||||||
|  | [[get-config]] | ||||||
|  | Get Config | ||||||
|  | ~~~~~~~~~~ | ||||||
|  | [verse] | ||||||
|  | 'GET /projects/link:#project-name[\{project-name\}]/config' | ||||||
|  |  | ||||||
|  | Gets some configuration information about a project. Note that this | ||||||
|  | config info is not simply the contents of `project.config`; it generally | ||||||
|  | contains fields that may have been inherited from parent projects. | ||||||
|  |  | ||||||
|  | .Request | ||||||
|  | ---- | ||||||
|  |   GET /projects/myproject/config | ||||||
|  | ---- | ||||||
|  |  | ||||||
|  | A link:#config-info[ConfigInfo] entity is returned that describes the | ||||||
|  | project configuration. Some fields are only visible to users that have | ||||||
|  | read access to `refs/meta/config`. | ||||||
|  |  | ||||||
|  | .Response | ||||||
|  | ---- | ||||||
|  |   HTTP/1.1 200 OK | ||||||
|  |   Content-Disposition: attachment | ||||||
|  |   Content-Type: application/json;charset=UTF-8 | ||||||
|  |  | ||||||
|  |   )]}' | ||||||
|  |   { | ||||||
|  |     "kind": "gerritcodereview#project_config", | ||||||
|  |     "use_contributor_agreements": false, | ||||||
|  |     "use_content_merge": true, | ||||||
|  |     "use_signed_off_by": false, | ||||||
|  |     "require_change_id": true | ||||||
|  |   } | ||||||
|  | ---- | ||||||
|  |  | ||||||
| [[run-gc]] | [[run-gc]] | ||||||
| Run GC | Run GC | ||||||
| ~~~~~~ | ~~~~~~ | ||||||
| @@ -896,6 +931,35 @@ statistics of a Git repository. | |||||||
| |`size_of_packed_objects`  |Size of packed objects in bytes. | |`size_of_packed_objects`  |Size of packed objects in bytes. | ||||||
| |====================================== | |====================================== | ||||||
|  |  | ||||||
|  | [[config-info]] | ||||||
|  | ConfigInfo | ||||||
|  | ~~~~~~~~~~ | ||||||
|  | The `ConfigInfo` entity contains information about the effective project | ||||||
|  | configuration. | ||||||
|  |  | ||||||
|  | Fields marked with * are only visible to users who have read access to | ||||||
|  | `refs/meta/config`. | ||||||
|  |  | ||||||
|  | [options="header",width="50%",cols="1,6"] | ||||||
|  | |====================================== | ||||||
|  | |Field Name                   |Description | ||||||
|  | |`use_contributor_agreements*`| | ||||||
|  | If set, authors must complete a contributor agreement on the site | ||||||
|  | before pushing any commits or changes to this project. | ||||||
|  | |`use_content_merge*`| | ||||||
|  | If set, Gerrit will try to perform a 3-way merge of text file content | ||||||
|  | when a file has been modified by both the destination branch and the | ||||||
|  | change being submitted. This option only takes effect if submit type is | ||||||
|  | not FAST_FORWARD_ONLY. | ||||||
|  | |`use_signed_off_by*`| | ||||||
|  | If set, each change must contain a Signed-off-by line from either the | ||||||
|  | author or the uploader in the commit message. | ||||||
|  | |`require_change_id*`| | ||||||
|  | If set, require a valid link:user-changeid.html[Change-Id] footer in any | ||||||
|  | commit uploaded for review. This does not apply to commits pushed | ||||||
|  | directly to a branch or tag. | ||||||
|  | |====================================== | ||||||
|  |  | ||||||
|  |  | ||||||
| GERRIT | GERRIT | ||||||
| ------ | ------ | ||||||
|   | |||||||
| @@ -0,0 +1,44 @@ | |||||||
|  | // Copyright (C) 2013 The Android Open Source Project | ||||||
|  | // | ||||||
|  | // Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
|  | // you may not use this file except in compliance with the License. | ||||||
|  | // You may obtain a copy of the License at | ||||||
|  | // | ||||||
|  | // http://www.apache.org/licenses/LICENSE-2.0 | ||||||
|  | // | ||||||
|  | // Unless required by applicable law or agreed to in writing, software | ||||||
|  | // distributed under the License is distributed on an "AS IS" BASIS, | ||||||
|  | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
|  | // See the License for the specific language governing permissions and | ||||||
|  | // limitations under the License. | ||||||
|  |  | ||||||
|  | package com.google.gerrit.server.project; | ||||||
|  |  | ||||||
|  | import com.google.gerrit.extensions.restapi.RestReadView; | ||||||
|  | import com.google.gerrit.server.git.GitRepositoryManager; | ||||||
|  |  | ||||||
|  | public class GetConfig implements RestReadView<ProjectResource> { | ||||||
|  |   public static class ConfigInfo { | ||||||
|  |     public final String kind = "gerritcodereview#project_config"; | ||||||
|  |  | ||||||
|  |     public Boolean useContributorAgreements; | ||||||
|  |     public Boolean useContentMerge; | ||||||
|  |     public Boolean useSignedOffBy; | ||||||
|  |     public Boolean requireChangeId; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   @Override | ||||||
|  |   public ConfigInfo apply(ProjectResource resource) { | ||||||
|  |     ConfigInfo result = new ConfigInfo(); | ||||||
|  |     RefControl refConfig = resource.getControl() | ||||||
|  |         .controlForRef(GitRepositoryManager.REF_CONFIG); | ||||||
|  |     ProjectState project = resource.getControl().getProjectState(); | ||||||
|  |     if (refConfig.isVisible()) { | ||||||
|  |       result.useContributorAgreements = project.isUseContributorAgreements(); | ||||||
|  |       result.useContentMerge = project.isUseContentMerge(); | ||||||
|  |       result.useSignedOffBy = project.isUseSignedOffBy(); | ||||||
|  |       result.requireChangeId = project.isRequireChangeID(); | ||||||
|  |     } | ||||||
|  |     return result; | ||||||
|  |   } | ||||||
|  | } | ||||||
| @@ -51,5 +51,7 @@ public class Module extends RestApiModule { | |||||||
|     put(DASHBOARD_KIND).to(SetDashboard.class); |     put(DASHBOARD_KIND).to(SetDashboard.class); | ||||||
|     delete(DASHBOARD_KIND).to(DeleteDashboard.class); |     delete(DASHBOARD_KIND).to(DeleteDashboard.class); | ||||||
|     install(new FactoryModuleBuilder().build(CreateProject.Factory.class)); |     install(new FactoryModuleBuilder().build(CreateProject.Factory.class)); | ||||||
|  |  | ||||||
|  |     get(PROJECT_KIND, "config").to(GetConfig.class); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Dave Borowitz
					Dave Borowitz