|
3 | 3 |
|
4 | 4 | https://bintray.com/docs/api |
5 | 5 | """ |
6 | | -import json |
7 | 6 | import os |
8 | 7 |
|
9 | 8 | from bintray.requester import Requester |
@@ -1066,3 +1065,130 @@ def delete_ip_restrictions(self, subject, repo): |
1066 | 1065 | response = self._requester.delete(url) |
1067 | 1066 | self._logger.info("Update successfully") |
1068 | 1067 | return response |
| 1068 | + |
| 1069 | + # Versions |
| 1070 | + |
| 1071 | + def get_version(self, subject, repo, package, version="_latest", attribute_values=True): |
| 1072 | + """ Get general information about a specified version, or query for the latest version that |
| 1073 | + has at least one file published to it. |
| 1074 | +
|
| 1075 | + :param subject: repository owner |
| 1076 | + :param repo: repository name |
| 1077 | + :param package: package name |
| 1078 | + :param version: package version |
| 1079 | + :param attribute_values: show attributes |
| 1080 | + :return: request response + package version information |
| 1081 | + """ |
| 1082 | + url = "{}/packages/{}/{}/{}/versions/{}".format(Bintray.BINTRAY_URL, subject, repo, |
| 1083 | + package, version) |
| 1084 | + params = {"attribute_values": bool_to_number(attribute_values)} |
| 1085 | + response = self._requester.get(url, params=params) |
| 1086 | + self._logger.info("Get successfully") |
| 1087 | + return response |
| 1088 | + |
| 1089 | + def create_version(self, subject, repo, package, version, description=None, |
| 1090 | + released=None, github_release_notes_file=None, |
| 1091 | + github_use_tag_release_notes=None, vcs_tag=None): |
| 1092 | + """ Creates a new version in the specified package (user has to be owner of the package) |
| 1093 | +
|
| 1094 | + Security: Authenticated user with 'publish' permission, or package read/write |
| 1095 | + entitlement. |
| 1096 | +
|
| 1097 | + :param subject: repository owner |
| 1098 | + :param repo: repository name |
| 1099 | + :param package: package name |
| 1100 | + :param version: version name |
| 1101 | + :param description: version description |
| 1102 | + :param released: release date ISO8601 |
| 1103 | + :param github_release_notes_file: file path for release notes e.g. RELEASE.txt |
| 1104 | + :param github_use_tag_release_notes: True when contain release notes file |
| 1105 | + :param vcs_tag: tag name in VCS |
| 1106 | + :return: request response |
| 1107 | + """ |
| 1108 | + url = "{}/packages/{}/{}/{}/versions".format(Bintray.BINTRAY_URL, subject, repo, package) |
| 1109 | + json_data = {'name': version} |
| 1110 | + if isinstance(description, str): |
| 1111 | + json_data["desc"] = description |
| 1112 | + if isinstance(released, str): |
| 1113 | + json_data["released"] = released |
| 1114 | + if isinstance(github_release_notes_file, str): |
| 1115 | + json_data["github_release_notes_file"] = github_release_notes_file |
| 1116 | + if isinstance(github_use_tag_release_notes, bool): |
| 1117 | + json_data["github_use_tag_release_notes"] = github_use_tag_release_notes |
| 1118 | + if isinstance(vcs_tag, str): |
| 1119 | + json_data["vcs_tag"] = vcs_tag |
| 1120 | + |
| 1121 | + response = self._requester.post(url, json=json_data) |
| 1122 | + self._logger.info("Create successfully") |
| 1123 | + return response |
| 1124 | + |
| 1125 | + def delete_version(self, subject, repo, package, version): |
| 1126 | + """ Delete the specified version |
| 1127 | +
|
| 1128 | + Security: Authenticated user with 'publish' permission, or package read/write |
| 1129 | + entitlement. |
| 1130 | +
|
| 1131 | + param subject: repository owner |
| 1132 | + :param repo: repository name |
| 1133 | + :param package: package name |
| 1134 | + :param version: version to be deleted |
| 1135 | + :return: request response |
| 1136 | + """ |
| 1137 | + url = "{}/packages/{}/{}/{}/versions/{}".format(Bintray.BINTRAY_URL, subject, repo, package, |
| 1138 | + version) |
| 1139 | + |
| 1140 | + response = self._requester.delete(url) |
| 1141 | + self._logger.info("Delete successfully") |
| 1142 | + return response |
| 1143 | + |
| 1144 | + def update_version(self, subject, repo, package, version, description=None, |
| 1145 | + github_release_notes_file=None, github_use_tag_release_notes=None, |
| 1146 | + vcs_tag=None): |
| 1147 | + """ Update the information of the specified version |
| 1148 | +
|
| 1149 | + Security: Authenticated user with 'publish' permission, or package read/write |
| 1150 | + entitlement. |
| 1151 | +
|
| 1152 | + :param subject: repository owner |
| 1153 | + :param repo: repository name |
| 1154 | + :param package: package name |
| 1155 | + :param version: version name to be updated |
| 1156 | + :param description: version description |
| 1157 | + :param github_release_notes_file: file path for release notes e.g. RELEASE.txt |
| 1158 | + :param github_use_tag_release_notes: True when contain release notes file |
| 1159 | + :param vcs_tag: tag name in VCS |
| 1160 | + :return: request response |
| 1161 | + """ |
| 1162 | + url = "{}/packages/{}/{}/{}/versions/{}".format(Bintray.BINTRAY_URL, subject, repo, |
| 1163 | + package, version) |
| 1164 | + json_data = {} |
| 1165 | + if isinstance(description, str): |
| 1166 | + json_data["desc"] = description |
| 1167 | + if isinstance(github_release_notes_file, str): |
| 1168 | + json_data["github_release_notes_file"] = github_release_notes_file |
| 1169 | + if isinstance(github_use_tag_release_notes, bool): |
| 1170 | + json_data["github_use_tag_release_notes"] = github_use_tag_release_notes |
| 1171 | + if isinstance(vcs_tag, str): |
| 1172 | + json_data["vcs_tag"] = vcs_tag |
| 1173 | + |
| 1174 | + if not json_data: |
| 1175 | + raise ValueError("At lease one parameter must be filled.") |
| 1176 | + |
| 1177 | + response = self._requester.patch(url, json=json_data) |
| 1178 | + self._logger.info("Create successfully") |
| 1179 | + return response |
| 1180 | + |
| 1181 | + def version_for_file(self, subject, repo, file_path): |
| 1182 | + """ Get general information about the version a repository file is associated with. |
| 1183 | +
|
| 1184 | + Security: Non-authenticated user. |
| 1185 | +
|
| 1186 | + :param subject: repository owner |
| 1187 | + :param repo: repository name |
| 1188 | + :param file_path: associated file path |
| 1189 | + :return: request response |
| 1190 | + """ |
| 1191 | + url = "{}/file_version/{}/{}/{}".format(Bintray.BINTRAY_URL, subject, repo, file_path) |
| 1192 | + response = self._requester.get(url) |
| 1193 | + self._logger.info("Get successfully") |
| 1194 | + return response |
0 commit comments