Skip to content

Commit ae272cb

Browse files
committed
Update alpha build message
1 parent 8f06a50 commit ae272cb

14 files changed

Lines changed: 194 additions & 58 deletions

File tree

.idea/kotlinc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle.kts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import com.google.firebase.appdistribution.gradle.firebaseAppDistribution
1414
import com.orange.ouds.gradle.Environment
1515
import com.orange.ouds.gradle.execute
1616
import com.orange.ouds.gradle.findTypedProperty
17-
import com.orange.ouds.gradle.gitHubApi
17+
import com.orange.ouds.gradle.gitHubGraphQLApi
18+
import com.orange.ouds.gradle.gitHubRestApi
1819
import com.orange.ouds.gradle.updateChangelog
1920

2021
plugins {
@@ -153,18 +154,23 @@ fun updateBuildConfig() {
153154
val tokensVersion = findTypedProperty<String>("tokensVersion").orEmpty()
154155

155156
val gitHubWorkflow = Environment.getVariablesOrNull("GITHUB_WORKFLOW").first()
156-
val pullRequestNumber = if (gitHubWorkflow == "app-distribution-alpha") {
157-
gitHubApi {
157+
val issueNumbers = if (gitHubWorkflow == "app-distribution-alpha") {
158+
gitHubRestApi {
158159
val pullRequests = getPullRequests()
159-
pullRequests.firstOrNull { it.branchName == Environment.branchName }?.number
160+
pullRequests.firstOrNull { it.branchName == Environment.branchName }
161+
?.let { pullRequest ->
162+
gitHubGraphQLApi {
163+
getPullRequestClosingIssues(pullRequest.number).map { it.number }
164+
}
165+
}
160166
}
161167
} else {
162168
null
163169
}
164170

165171
android.defaultConfig {
166172
buildConfigField("String", "TOKENS_VERSION", "\"$tokensVersion\"")
167-
buildConfigField("String", "PULL_REQUEST_NUMBER", if (pullRequestNumber != null) "\"$pullRequestNumber\"" else "null")
173+
buildConfigField("int[]", "ISSUE_NUMBERS", if (issueNumbers != null) "new int[]{${issueNumbers.joinToString(", ")}}" else "null")
168174
}
169175
}
170176

app/src/main/java/com/orange/ouds/app/ui/about/AboutScreen.kt

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import androidx.compose.material3.Text
2929
import androidx.compose.runtime.Composable
3030
import androidx.compose.ui.Modifier
3131
import androidx.compose.ui.platform.LocalContext
32+
import androidx.compose.ui.res.pluralStringResource
3233
import androidx.compose.ui.res.stringResource
3334
import androidx.compose.ui.text.LinkAnnotation
3435
import androidx.compose.ui.text.SpanStyle
@@ -79,23 +80,28 @@ fun AboutScreen(onMenuItemClick: (id: Int) -> Unit) {
7980
LazyColumn {
8081
item {
8182
val version = stringResource(R.string.app_about_version_label, BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE.toLong())
82-
val pullRequestNumber: String? = BuildConfig.PULL_REQUEST_NUMBER
83+
val issueNumbers: IntArray? = BuildConfig.ISSUE_NUMBERS
8384
ListItem(
8485
modifier = Modifier.listItemHorizontalPadding(),
8586
headlineContent = {
8687
Column(verticalArrangement = Arrangement.spacedBy(OudsTheme.spaces.fixed.small)) {
8788
Text(text = stringResource(id = R.string.app_about_name_label), style = OudsTheme.typography.heading.extraLarge)
8889
Text(text = version, style = OudsTheme.typography.body.default.large)
89-
if (pullRequestNumber != null) {
90-
val pullRequest = buildAnnotatedString {
91-
append(stringResource(R.string.app_about_pullRequest_label))
92-
withLink(LinkAnnotation.Url("https://github.com/Orange-OpenSource/ouds-android/pull/$pullRequestNumber")) {
93-
withStyle(SpanStyle(OudsTheme.colorScheme.content.brandPrimary)) {
94-
append(stringResource(R.string.app_about_pullRequestNumber_label, pullRequestNumber))
90+
if (issueNumbers != null) {
91+
val issues = buildAnnotatedString {
92+
append(pluralStringResource(R.plurals.app_about_issues_label, issueNumbers.count()))
93+
issueNumbers.forEachIndexed { index, issueNumber ->
94+
if (index >= 1) {
95+
append(" ")
96+
}
97+
withLink(LinkAnnotation.Url("https://github.com/Orange-OpenSource/ouds-android/issues/$issueNumber")) {
98+
withStyle(SpanStyle(OudsTheme.colorScheme.content.brandPrimary)) {
99+
append(stringResource(R.string.app_about_issueNumber_label, issueNumber))
100+
}
95101
}
96102
}
97103
}
98-
Text(text = pullRequest, style = OudsTheme.typography.body.default.medium)
104+
Text(text = issues, style = OudsTheme.typography.body.default.medium)
99105
}
100106
Text(
101107
text = stringResource(R.string.app_about_tokensVersion_label, BuildConfig.TOKENS_VERSION),

app/src/main/res/values-ar/strings.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,14 @@
185185

186186
<!-- About -->
187187
<string name="app_about_name_label">أدوات نظام التصميم</string>
188-
<string name="app_about_pullRequest_label">طلب السحب</string>
189-
<string name="app_about_pullRequestNumber_label">#%s</string>
188+
<plurals name="app_about_issues_label">
189+
<item quantity="zero">Issue\u0020</item>
190+
<item quantity="one">Issues\u0020</item>
191+
<item quantity="two">Issues\u0020</item>
192+
<item quantity="few">Issues\u0020</item>
193+
<item quantity="many">Issues\u0020</item>
194+
</plurals>
195+
<string name="app_about_issueNumber_label">#%s</string>
190196
<string name="app_about_tokensVersion_label">إصدار الرموز %s</string>
191197
<string name="app_about_privacyPolicy_label">سياسة الخصوصية</string>
192198
<string name="app_about_legalInformation_label">المعلومات القانونية</string>

app/src/main/res/values/strings.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,11 @@
196196

197197
<!-- About -->
198198
<string name="app_about_name_label">Design System Toolbox</string>
199-
<string name="app_about_pullRequest_label">Pull request\u0020</string>
200-
<string name="app_about_pullRequestNumber_label">#%s</string>
199+
<plurals name="app_about_issues_label">
200+
<item quantity="one">Issue\u0020</item>
201+
<item quantity="other">Issues\u0020</item>
202+
</plurals>
203+
<string name="app_about_issueNumber_label">#%s</string>
201204
<string name="app_about_tokensVersion_label">Tokens version %s</string>
202205
<string name="app_about_privacyPolicy_label">Privacy policy</string>
203206
<string name="app_about_legalInformation_label">Legal information</string>

buildSrc/src/main/kotlin/com/orange/ouds/gradle/FirebaseApi.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class FirebaseApi(accessToken: String, projectNumber: String, appId: String) : A
3939
return List(jsonReleases.length()) { index ->
4040
with(jsonReleases.getJSONObject(index)) {
4141
FirebaseAppDistributionRelease(
42+
displayVersion = getString("displayVersion"),
4243
buildVersion = getString("buildVersion").toInt(),
4344
binaryDownloadUri = getString("binaryDownloadUri")
4445
)

buildSrc/src/main/kotlin/com/orange/ouds/gradle/FirebaseEntities.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
package com.orange.ouds.gradle
1414

1515
data class FirebaseAppDistributionRelease(
16+
val displayVersion: String,
1617
val buildVersion: Int,
1718
val binaryDownloadUri: String,
1819
)

buildSrc/src/main/kotlin/com/orange/ouds/gradle/GitHubEntities.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,8 @@ data class GitHubIssueComment(
2222
val id: Long,
2323
val body: String,
2424
)
25+
26+
data class GitHubIssue(
27+
val number: Int,
28+
val title: String
29+
)
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Software Name: OUDS Android
3+
* SPDX-FileCopyrightText: Copyright (c) Orange SA
4+
* SPDX-License-Identifier: MIT
5+
*
6+
* This software is distributed under the MIT license,
7+
* the text of which is available at https://opensource.org/license/MIT/
8+
* or see the "LICENSE" file for more details.
9+
*
10+
* Software description: Android library of reusable graphical components
11+
*/
12+
13+
package com.orange.ouds.gradle
14+
15+
import org.gradle.api.Project
16+
import org.json.JSONObject
17+
18+
class GitHubGraphQLApi(token: String, private val owner: String, private val name: String) : Api() {
19+
20+
override val baseUrl = "https://api.github.com"
21+
22+
override val headers = mapOf("Authorization" to listOf("Bearer $token"))
23+
24+
fun Project.getPullRequestClosingIssues(pullRequestNumber: Int): List<GitHubIssue> {
25+
val query = """query {
26+
repository(owner: \"$owner\", name: \"${this@GitHubGraphQLApi.name}\") {
27+
pullRequest(number: $pullRequestNumber) {
28+
closingIssuesReferences(first: 100) {
29+
nodes {
30+
number
31+
title
32+
}
33+
}
34+
}
35+
}
36+
}""".replace("\n\\s*".toRegex(), " ")
37+
val body = "{ \"query\": \"$query\" }"
38+
val jsonString = launchGraphQLRequest(body)
39+
40+
return parsePullRequestClosingIssues(jsonString)
41+
}
42+
43+
private fun Project.launchGraphQLRequest(body: String? = null) = launchRequest("graphql", "POST", body)
44+
45+
private fun parsePullRequestClosingIssues(jsonString: String): List<GitHubIssue> {
46+
val jsonIssues = JSONObject(jsonString)
47+
.getJSONObject("data")
48+
.getJSONObject("repository")
49+
.getJSONObject("pullRequest")
50+
.getJSONObject("closingIssuesReferences")
51+
.getJSONArray("nodes")
52+
53+
return List(jsonIssues.length()) { index ->
54+
with(jsonIssues.getJSONObject(index)) {
55+
GitHubIssue(
56+
number = getInt("number"),
57+
title = getString("title")
58+
)
59+
}
60+
}
61+
}
62+
}

buildSrc/src/main/kotlin/com/orange/ouds/gradle/GitHubApi.kt renamed to buildSrc/src/main/kotlin/com/orange/ouds/gradle/GitHubRestApi.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import java.io.File
1919
import kotlin.io.encoding.Base64
2020
import kotlin.io.encoding.ExperimentalEncodingApi
2121

22-
class GitHubApi(token: String, repository: String) : Api() {
22+
class GitHubRestApi(token: String, repository: String) : Api() {
2323

2424
override val baseUrl = "https://api.github.com/repos/$repository"
2525

0 commit comments

Comments
 (0)