Skip to content

Commit

Permalink
feat(codemagic_app_preview): add --qr-code-size option (#104)
Browse files Browse the repository at this point in the history
* Adds the option `--qr-code-size` to specify the size of the QR code in
pixels as an integer. The default value is 200.
* Increases the default size of a qr code from 150 to 200.

Fixes #103
  • Loading branch information
nilsreichardt authored Nov 16, 2023
1 parent dd525eb commit 05a0232
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/codemagic_app_preview/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ If you are interested in supporting self-hosted GitLab, Bitbucket or a different
|  `--message` | Optional | Custom message to include in the comment. | "Only team members are able to install the iOS app.", see [this example](https://github.com/SharezoneApp/sharezone-app/pull/1095#issuecomment-1733715519). |
|  `--expires_in` | Optional | Defines the duration for which the URLs to the artifacts are valid. The maximum duration depends on your account type, see [Codemagic documentation](https://docs.codemagic.io/billing/pricing/#build-history-and-artifact-storage). The default value is 30 days. | `2w 6d 23h 59m 59s` or `365d` |
| `--app_name` | Optional | The name of the app. This is helpful if you have multiple apps in the same repository. Using different names for different apps allows you to post multiple comments in the same pull request. | `sharezone` |
| `--qr-code-size` | Optional |  The size of the QR code in pixels as an integer. The default value is 200. | `500` or `400` |

## Quick Start Guide

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ class PostCommand extends Command {
'app-name',
help:
'The name of the app. This is helpful if you have multiple apps in the same repository. If not provided, the name "default" is used. Using different names for different apps allows you to post multiple comments in the same pull request.',
)
..addOption(
'qr-code-size',
help:
'The size of the QR code in pixels as an integer. The default value is 200. Example values: "100" or "500"',
defaultsTo: '200',
);
}

Expand Down Expand Up @@ -89,6 +95,7 @@ class PostCommand extends Command {
final comment = CommentBuilder(environmentVariableAccessor).build(
builds,
message: argResults?['message'],
qrCodeSize: int.parse(argResults?['qr-code-size']!),
);

final gitHostRepository = await _getGitHostRepository(gitRepo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ class CommentBuilder {
/// Builds a message that can be used a comment on a pull request.
String build(
List<Build> builds, {
required int qrCodeSize,
String? appName,
String? message,
}) {
final comment = StringBuffer();

final commit = _environmentVariableAccessor.get('FCI_COMMIT');
final table = _buildTable(builds);
final table = _buildTable(
builds,
qrCodeSize: qrCodeSize,
);

comment.write(
'⬇️ Builds generated by [Codemagic](https://codemagic.io) for commit $commit ⬇️');
Expand Down Expand Up @@ -50,7 +54,10 @@ class CommentBuilder {
/// |:-:|:-:|
/// | ![image](https://app-preview-qr.nils.re/?size=150x150&data=$LINK) <br /> [Download link]($LINK) | ![image](https://app-preview-qr.nils.re/?size=150x150&data=$ENCODED_IPA_LINK) <br /> [Download link]($LINK)
/// ```
String _buildTable(List<Build> builds) {
String _buildTable(
List<Build> builds, {
required int qrCodeSize,
}) {
final table = StringBuffer();

int columnsCounter = 0;
Expand Down Expand Up @@ -80,6 +87,7 @@ class CommentBuilder {
url: build.publicUrl,
groupId: groupId,
platform: build.platform,
qrCodeSize: qrCodeSize,
);

if (build.platform == BuildPlatform.macos) {
Expand Down Expand Up @@ -175,9 +183,10 @@ class CommentBuilder {
required String url,
required String groupId,
required BuildPlatform platform,
required int qrCodeSize,
}) {
// The url needs to be encoded to make it safe to use as a url component.
final encodedUrl = Uri.encodeComponent(url);
return 'https://app-preview-qr.nils.re/?size=150x150&data=$encodedUrl&platform=${platform.platformIdentifier}&groupId=$groupId';
return 'https://app-preview-qr.nils.re/?size=${qrCodeSize}x$qrCodeSize&data=$encodedUrl&platform=${platform.platformIdentifier}&groupId=$groupId';
}
}
7 changes: 4 additions & 3 deletions packages/codemagic_app_preview/test/comment_builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ void main() {
// The group id that is generated when using 42 as seed.
const groupId = "33aec45d";

expect(builder.build(builds),
expect(builder.build(builds, qrCodeSize: 351),
"""⬇️ Builds generated by [Codemagic](https://codemagic.io) for commit $commit ⬇️
| ${builds[0].platform.platformName} | | ${builds[1].platform.platformName} | | ${builds[2].platform.platformName} |
|:-:|:-:|:-:|:-:|:-:|
| ![Android QR code](https://app-preview-qr.nils.re/?size=150x150&data=${Uri.encodeComponent(builds[0].publicUrl)}&platform=android&groupId=$groupId) <br /> [Download link](${builds[0].publicUrl}) | | ![iOS QR code](https://app-preview-qr.nils.re/?size=150x150&data=${Uri.encodeComponent(builds[1].publicUrl)}&platform=ios&groupId=$groupId) <br /> [Download link](${builds[1].publicUrl}) | | <a href="${builds[2].publicUrl}"><img src="https://app-preview.nils.re/download-icon" alt="Download Icon"/></a> <br /> [Download link](${builds[2].publicUrl}) |
| ![Android QR code](https://app-preview-qr.nils.re/?size=351x351&data=${Uri.encodeComponent(builds[0].publicUrl)}&platform=android&groupId=$groupId) <br /> [Download link](${builds[0].publicUrl}) | | ![iOS QR code](https://app-preview-qr.nils.re/?size=351x351&data=${Uri.encodeComponent(builds[1].publicUrl)}&platform=ios&groupId=$groupId) <br /> [Download link](${builds[1].publicUrl}) | | <a href="${builds[2].publicUrl}"><img src="https://app-preview.nils.re/download-icon" alt="Download Icon"/></a> <br /> [Download link](${builds[2].publicUrl}) |
<sub>(expires Tue, 24 Jan 2023 11:10:09 GMT)<br/>Codemagic build: [$buildId](https://codemagic.io/app/$projectId/build/$buildId); comment generated with [Codemagic App Preview](https://github.com/nilsreichardt/codemagic-app-preview)</sub>
Expand All @@ -80,7 +80,8 @@ void main() {
];
final message = 'this is a custom message';

expect(builder.build(builds, message: message), contains(message));
expect(builder.build(builds, message: message, qrCodeSize: 150),
contains(message));
});
});
}

0 comments on commit 05a0232

Please sign in to comment.