Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add script for generating new API version #WPB-11975 #3097

Merged
merged 12 commits into from
Nov 20, 2024

Conversation

damian-kaczmarek
Copy link
Contributor

@damian-kaczmarek damian-kaczmarek commented Nov 8, 2024

TaskWPB-11975 [Android] Adopt API v7

What's new in this PR?

Issues

While implementing API v7 I noticed that we need to add many new classes in a repetitive way. Doing it manual is prone to errors.

Solutions

Added script that automates the process. Added comments about the script in a likely places that develop can start looking in.

Testing

How to Test

You can either run:

  • bash
    ./scripts/generate_new_api_version.sh 5 6 7
  • gradle task:
    ./gradlew :network:generateNewApiVersion -PpreviousApiVersion=5 -PcurrentApiVersion=6 -PnewApiVersion=7

It should generate NetworkContainers and API classes.
It should add the new api as BackendMetaDataUtil.DevelopmentApiVersions
There could be some unused params copied from previous API version that developer will need to remove, but static analysis will catch it.


PR Post Submission Checklist for internal contributors (Optional)

  • Wire's Github Workflow has automatically linked the PR to a JIRA issue

PR Post Merge Checklist for internal contributors

  • If any soft of configuration variable was introduced by this PR, it has been added to the relevant documents and the CI jobs have been updated.

References
  1. https://sparkbox.com/foundry/semantic_commit_messages
  2. https://github.com/wireapp/.github#usage
  3. E.g. feat(conversation-list): Sort conversations by most emojis in the title #SQPIT-764.

Copy link
Contributor

github-actions bot commented Nov 8, 2024

Test Results

3 289 tests  ±0   3 182 ✅ ±0   4m 31s ⏱️ -39s
  561 suites ±0     107 💤 ±0 
  561 files   ±0       0 ❌ ±0 

Results for commit 076411b. ± Comparison against base commit 3bf74f0.

♻️ This comment has been updated with latest results.

Copy link
Contributor

github-actions bot commented Nov 8, 2024

@codecov-commenter
Copy link

codecov-commenter commented Nov 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 54.07%. Comparing base (3bf74f0) to head (076411b).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #3097   +/-   ##
========================================
  Coverage    54.07%   54.07%           
========================================
  Files         1232     1232           
  Lines        36006    36012    +6     
  Branches      3653     3653           
========================================
+ Hits         19469    19475    +6     
+ Misses       15128    15127    -1     
- Partials      1409     1410    +1     
Files with missing lines Coverage Δ
...lin/com/wire/kalium/network/BackendMetaDataUtil.kt 100.00% <100.00%> (ø)
.../networkContainer/AuthenticatedNetworkContainer.kt 24.50% <ø> (ø)
...etworkContainer/UnauthenticatedNetworkContainer.kt 5.55% <ø> (ø)

... and 4 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3bf74f0...076411b. Read the comment docs.

---- 🚨 Try these New Features:

@datadog-wireapp
Copy link

datadog-wireapp bot commented Nov 8, 2024

Datadog Report

Branch report: chore/script-generate-new-api
Commit report: cef61e7
Test service: kalium-jvm

✅ 0 Failed, 3182 Passed, 107 Skipped, 31.87s Total Time

Copy link
Member

@MohamadJaara MohamadJaara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did run the script and it keeps constructor parameter modifiers like private val
it is better to remove them if they are not used inside the class
so maybe adding to the end of the copy api classes step will help
note: this Regex is from ChatGPT so take it with a grain of salt

      # Remove 'private val' from constructor parameters
      new_content=$(echo "$new_content" | perl -0777 -pe '
        s{
          (constructor\s*\()    # Match "constructor(" with optional whitespace
          (                     # Start capture group for parameters
            (?:                 # Non-capturing group
              [^()]             # Any character except parentheses
              |                 # OR
              \([^()]*\)        # Parentheses containing anything but parentheses
            )*?                 # Zero or more times, non-greedy
          )
          (\))                  # Match closing ")"
        }{
          my ($cons, $params, $close) = ($1, $2, $3);
          # Remove visibility modifiers and 'val' or 'var' from parameters
          $params =~ s/\b(private|public|protected|internal)\s+(val|var)\s+//g;
          "$cons$params$close"
        }egsx;
      ')

Copy link
Member

@vitorhugods vitorhugods left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the logic within generate_new_api_version.sh would be easier to maintain and expand if written in Kotlin, as it's what most of the team is used to. It would also run on Windows :c

We could even leverage tools like KotlinPoet to generate some pieces of code for us.


On the other hand... it's definitely an improvement over not having it at all. So yeah, if the other comments can be addressed, it's fine from my point of view :)

Copy link
Contributor

@borichellow borichellow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree with existed comments, other then that: I like the idea, definitely improvement of life 👍 💪

@damian-kaczmarek
Copy link
Contributor Author

I have added removing vals. I did not found a way to remove unused params without installing detekt CLI to run the autofix on a directory. 🤔

Added a task to rewrite it in Kotlin. I didn't used the KotlinPoet yet, looks fun https://wearezeta.atlassian.net/browse/WPB-14423

…/script-generate-new-api

# Conflicts:
#	network/src/commonMain/kotlin/com/wire/kalium/network/BackendMetaDataUtil.kt
#	network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/AccessTokenApiV6.kt
#	network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/AuthenticatedNetworkContainer.kt
#	network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/UnauthenticatedNetworkContainer.kt
@damian-kaczmarek damian-kaczmarek added this pull request to the merge queue Nov 20, 2024
Merged via the queue into develop with commit 44c4ccb Nov 20, 2024
22 checks passed
@damian-kaczmarek damian-kaczmarek deleted the chore/script-generate-new-api branch November 20, 2024 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants