Skip to content

Commit bd55851

Browse files
authored
chore: add explicit permissions to gh workflows and update lints (#126)
* ci: add explicit permissions to github workflows - Add `contents: read` and `pull-requests: write` permissions to analyze workflow - Add `contents: read` permission to backup workflow - Add `contents: write` permission to publish workflow - Add `contents: read` permission to test workflow * chore(lint): enable additional dcm rules and update dependencies - Enable shorthand preference rules that were previously disabled - Enable new metrics rules: avoid-missing-test-files, avoid-unassigned-local-variable, avoid-undisposed-instances, avoid-unnecessary-parentheses, prefer-non-nulls - Disable avoid-throw rule due to breaking change and use of maybe* methods - Update dart_code_metrics_presets to ^2.30.0 - Update test to ^1.31.0 - Update SDK constraint to ^3.11.3 - Fix RegExp instantiation to use shorthand syntax - Update example code to use maybeMapStatusCode with proper parameter handling * chore: refactor workflow permissions and update readme - Move `contents: write` permission from global to `check-version` job only - Reorder debug configurations in `.zed/debug.json` for consistency - Add GitHub issues badge to README - Update test count from 1000 to 1120 in documentation - Clarify industry adoption timeline (remove specific year reference) - Add verified publisher feature to README - Fix status code variable reference in example code
1 parent ec80c1e commit bd55851

12 files changed

Lines changed: 57 additions & 30 deletions

File tree

.github/workflows/analyze.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ on:
1111
- "pubspec.yaml"
1212
- ".github/workflows/analyze.yaml"
1313

14+
permissions:
15+
contents: read
16+
pull-requests: write
17+
1418
jobs:
1519
analysis:
1620
name: 🕵️ Analyze

.github/workflows/backup.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ on:
55
branches:
66
- main
77

8+
permissions:
9+
contents: read
10+
811
jobs:
912
mirror-to-gitlab:
1013
name: 💾 Backup to GitLab

.github/workflows/publish.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ jobs:
3434
check-version:
3535
name: 💡 Check version
3636
runs-on: ubuntu-latest
37+
permissions:
38+
contents: write
3739
if: github.ref_type == 'tag'
3840
timeout-minutes: 10
3941
steps:

.github/workflows/test.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ on:
2020
- "pubspec.yaml"
2121
- ".github/workflows/test.yaml"
2222

23+
permissions:
24+
contents: read
25+
2326
jobs:
2427
test:
2528
name: 🧪 Test

.zed/debug.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
[
22
{
33
"adapter": "Dart",
4-
"label": "Run example (simple)",
4+
"label": "Run example (real client)",
55
"type": "dart",
6-
"args": ["--simple"],
76
"request": "launch",
87
"program": "$ZED_WORKTREE_ROOT/example/lib/main.dart"
98
},
109
{
1110
"adapter": "Dart",
12-
"label": "Run example (real client)",
11+
"label": "Run example (simple)",
1312
"type": "dart",
1413
"request": "launch",
15-
"program": "$ZED_WORKTREE_ROOT/example/lib/main.dart"
14+
"program": "$ZED_WORKTREE_ROOT/example/lib/main.dart",
15+
"args": [
16+
"--simple"
17+
]
1618
}
1719
]

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[![CodeFactor](https://www.codefactor.io/repository/github/tsinis/functional_status_codes/badge)](https://www.codefactor.io/repository/github/tsinis/functional_status_codes)
55
[![Pub points](https://img.shields.io/pub/points/functional_status_codes)](https://pub.dev/packages/functional_status_codes/score)
66
[![Created](https://img.shields.io/github/created-at/tsinis/functional_status_codes)](https://github.com/tsinis/functional_status_codes/commit/23d35c4fc890d01b8dc93409738e4fc61712e94f)
7+
[![GitHub issues](https://img.shields.io/github/issues-raw/tsinis/functional_status_codes)](https://github.com/tsinis/functional_status_codes/issues?q=is%3Aissue+is%3Aopen)
78
![CodeRabbit Pull Request Reviews](https://img.shields.io/coderabbit/prs/github/tsinis/functional_status_codes?utm_source=oss&utm_medium=github&utm_campaign=tsinis%2Ffunctional_status_codes&labelColor=171717&color=FF570A&link=https%3A%2F%2Fcoderabbit.ai&label=CodeRabbit+Reviews)
89
[![License](https://img.shields.io/badge/License-BSD_3--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)
910
[![Size](https://img.shields.io/github/languages/code-size/tsinis/functional_status_codes)](https://github.com/tsinis/functional_status_codes#why-should-i-use-this-package)
@@ -139,9 +140,9 @@ The use of `StatusCode` extension type and boolean getters (`isInformational`, `
139140

140141
10. **No 3rd-party dependencies**: This package has no third-party dependencies, ensuring that you won't have any issues or conflicts with other dependencies (no even `meta` here, because of that).
141142

142-
11. **High code coverage**: The code in this package has almost 100% code coverage, with more than 1000 tests, providing confidence in its reliability and stability.
143+
11. **High code coverage**: The code in this package has almost 100% code coverage, with more than 1120 tests, providing confidence in its reliability and stability.
143144

144-
12. **Industry adopted**: This package is actively used (since 2022) in production by numerous European companies, ensuring its efficacy and robustness in real-world scenarios.
145+
12. **Industry adopted**: This package is actively used (for years) in production by numerous European companies, ensuring its efficacy and robustness in real-world scenarios.
145146

146147
13. **BSD-3-Clause License**: This package and sources are released under the BSD-3-Clause license, a permissive license that is also used by the Dart and Flutter SDKs. It allows users to use, modify, and distribute the code with minimal restrictions.
147148

@@ -151,6 +152,8 @@ The use of `StatusCode` extension type and boolean getters (`isInformational`, `
151152

152153
16. **Mirrored Repository**: The GitHub repository, including all package tags, is mirrored on [GitLab](https://gitlab.com/tsinis/functional_status_codes/), providing an alternative access point should GitHub become unavailable.
153154

155+
17. **Verified publisher**: Published and maintained under an active, verified pub.dev publisher account since 2022.
156+
154157
By using these features of the `functional_status_codes` package, you promote a more robust, readable, and maintainable approach to HTTP status code handling in your Dart projects.
155158

156159
### Getting started

analysis_options.yaml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,12 @@ dart_code_metrics:
122122
min-occurrences: 4
123123

124124
# Disabled:
125-
# Shorthands:
126-
- prefer-returning-shorthands: false
127-
- prefer-shorthands-with-constructors: false
128-
- prefer-shorthands-with-enums: false
129-
- prefer-shorthands-with-static-fields: false
130-
# Other disabled:
131125
- arguments-ordering: false # This will be a breaking change.
132126
- avoid-continue: false # Just a matter of style.
133127
- avoid-deprecated-usage: false # Using default deprecated_member_use_from_same_package.
134128
- avoid-inferrable-type-arguments: false # Against prefer-explicit-type-arguments.
135129
- avoid-long-files: false # A lot of data and collections.
130+
- avoid-throw: false # Breaking change + we have maybe* methods.
136131
- no-magic-number: false # Packages contain a lot of numbers.
137132
- no-magic-string: false # Packages contain a lot of strings.
138133
- parameters-ordering: false # This will be a breaking change.
@@ -218,6 +213,7 @@ dart_code_metrics:
218213
- avoid-missing-completer-stack-trace: true
219214
- avoid-missing-enum-constant-in-map: true
220215
- avoid-missing-interpolation: true
216+
- avoid-missing-test-files: true
221217
- avoid-misused-set-literals: true
222218
- avoid-misused-test-matchers: true
223219
- avoid-misused-wildcard-pattern: true
@@ -276,9 +272,11 @@ dart_code_metrics:
276272
- avoid-type-casts: true
277273
- avoid-unassigned-fields: true
278274
- avoid-unassigned-late-fields: true
275+
- avoid-unassigned-local-variable: true
279276
- avoid-unassigned-stream-subscriptions: true
280277
- avoid-uncaught-future-errors: true
281278
- avoid-unconditional-break: true
279+
- avoid-undisposed-instances: true
282280
- avoid-unknown-pragma: true
283281
- avoid-unnecessary-block: true
284282
- avoid-unnecessary-call: true
@@ -304,6 +302,7 @@ dart_code_metrics:
304302
- avoid-unnecessary-nullable-parameters: true
305303
- avoid-unnecessary-nullable-return-type: true
306304
- avoid-unnecessary-overrides: true
305+
- avoid-unnecessary-parentheses: true
307306
- avoid-unnecessary-patterns: true
308307
- avoid-unnecessary-reassignment: true
309308
- avoid-unnecessary-return: true
@@ -401,6 +400,7 @@ dart_code_metrics:
401400
- prefer-match-file-name: true
402401
- prefer-moving-to-variable: true
403402
- prefer-named-boolean-parameters: true
403+
- prefer-non-nulls: true
404404
- prefer-null-aware-elements: true
405405
- prefer-null-aware-spread: true
406406
- prefer-overriding-parent-equality: true
@@ -413,6 +413,10 @@ dart_code_metrics:
413413
- prefer-return-await: true
414414
- prefer-returning-condition: true
415415
- prefer-returning-conditional-expressions: true
416+
- prefer-returning-shorthands: true
417+
- prefer-shorthands-with-constructors: true
418+
- prefer-shorthands-with-enums: true
419+
- prefer-shorthands-with-static-fields: true
416420
- prefer-simpler-boolean-expressions: true
417421
- prefer-simpler-patterns-null-check: true
418422
- prefer-single-declaration-per-file: true
@@ -658,4 +662,4 @@ linter:
658662
use_to_and_as_if_applicable: true
659663
use_truncating_division: true
660664
valid_regexps: true
661-
void_checks: true
665+
void_checks: true

example/analysis_options.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include: ../analysis_options.yaml
1+
include: ../analysis_options.yaml

example/lib/main.dart

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,13 @@ Future<int?> _realClient(List<String> arguments, [http.Client? client]) async {
8585

8686
// If the status code is a success status code, check if it is a 201
8787
// (Created) or 200 (OK) code.
88-
return response.statusCode.maybeWhenStatusCode(
89-
isSuccess: () {
88+
return response.statusCode.maybeMapStatusCode(
89+
isSuccess: (successStatus) {
9090
// If the status code is success one, convert it to a registered
9191
// status code object.
92-
final registeredCode = response.statusCode.toRegisteredStatusCode();
92+
final registeredCode = successStatus.toRegisteredStatusCode();
9393

94-
// Use the [StatusCode] type to determine the specific status code
95-
// type.
94+
// Use the [StatusCode] type to determine the specific status code type.
9695
return registeredCode?.maybeMap(
9796
createdHttp201: (status) {
9897
print('Response has registered success status but not 200 code');
@@ -114,19 +113,26 @@ Future<int?> _realClient(List<String> arguments, [http.Client? client]) async {
114113
print('Response has success status but not 200 code');
115114

116115
// Return the status code.
117-
return response.statusCode;
116+
return successStatus;
118117
},
119118
) ??
120119
// If the status code is not a registered status code, return the
121120
// status code.
122-
response.statusCode;
121+
successStatus;
123122
},
124-
orElse: () {
123+
isClientError: (errorStatus) {
124+
if (errorStatus.isOneOf(const [StatusCode.tooManyRequestsHttp429])) {
125+
print('Response has too many requests status :(');
126+
}
127+
128+
return errorStatus; // Return the status code.
129+
},
130+
orElse: (otherStatus) {
125131
// If the status code is not a success status code, print an error
126132
// message and return the status code.
127-
print('Request failed with status: ${response.statusCode}!');
133+
print('Request failed with status: $otherStatus!');
128134

129-
return response.statusCode;
135+
return otherStatus;
130136
},
131137
);
132138
}

example/pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ description: A simple one and modified http package example with use of function
33
publish_to: none
44

55
environment:
6-
sdk: ^3.11.1
6+
sdk: ^3.11.3
77

88
dependencies:
99
functional_status_codes:
1010
path: ../
1111
http: any # ignore: avoid-any-version, it's exampe app.
1212

1313
dev_dependencies:
14-
dart_code_metrics_presets: ^2.29.0 # DCM.
14+
dart_code_metrics_presets: ^2.30.0 # DCM.
1515
lints: ^6.1.0 # From Google.
16-
test: ^1.30.0 # From Google.
16+
test: ^1.31.0 # From Google.

0 commit comments

Comments
 (0)