codemagic_manager 0.2.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 45

codemagic_manager #

Simple unofficial api client to fetch builds and applications details from your Codemagic account

Getting Started #

Codemagic has recently exposed an API to access information about builds and applications. This is a simple wrapper to help you manage your builds.

API documentation #

First of all check the official Codemagic API docs here. The API is in preview and may change significantly during development period.

Using the client #

The library exposes CodemagicClient that is a HTTP client using dio to fetch and deserialize responses from Codemagic API.

To initialize the client you should call:

final client = CodemagicClient(
    apiUrl: 'https://api.codemagic.io',
    authKey: 'AUTH-KEY',
),

The AUTH-KEY as of now is available to get from your Codemagic account settings in User settings > Integrations > Codemagic API > Show.

Available methods #

Right now following endpoints are available

Get Builds

Object consisting of two sets of informations:

  • list of Applications
  • list of Builds
final buildsResponse = await client.getBuilds();
if (buildsResponse.wasSuccessful) {
    //handle buildsResponse.data
} else {
    //handle buildsResponse.error
}

Get Application

Specific informations about the given Application.

final appsResponse = await client.getApplication('application-id');
if (appsResponse.wasSuccessful) {
    //handle appsResponse.data
} else {
    //handle appsResponse.error
}

Work in progress #

This library is a work in progress. Some models are not generated yet and others may not be fully tested.

Contributions #

All the contributions are welcome! Please feel free to file issues or create PR if you would like to improve the library.

[0.2.0] - Starting and cancelling builds #

  • Added methods to start and cancel running build

[0.1.3] - Platform issues #

  • Fixed missing platforms

[0.1.2+1] - Package info #

  • Added some package information like issue tracker

[0.1.2] - Platforms #

  • Added missing platforms

[0.1.1+1] - Improvements #

  • Improve quality of code, document API etc.

[0.1.0] - Initial release 🎉 #

  • First version allowing to query applications and builds in a limited manner

example/lib/main.dart

import 'package:codemagic_manager/codemagic_manager.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Codemagic example',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key}) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  CodemagicClient client;
  final List<Build> builds = [];

  @override
  void initState() {
    super.initState();
    client = CodemagicClient(
      apiUrl: 'https://api.codemagic.io',
      authKey: 'd8C-Kuk4eUrdtYpgEWs1qA',
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Column(
          children: [
            RaisedButton(
              child: Text('Fetch builds'),
              onPressed: onFetch,
            ),
            if (builds.length > 0)
              RaisedButton(
                child: Text('Start latest build again'),
                onPressed: onStart,
              ),
            if (builds.length > 0)
              RaisedButton(
                child: Text('Cancel latest build'),
                onPressed: onCancel,
              ),
            Flexible(
              child: ListView.builder(
                itemCount: builds.length,
                itemBuilder: (context, index) => ListTile(
                  title: Text(builds[index].id ?? 'no id'),
                  subtitle:
                      Text(builds[index].status.toString() ?? 'no status'),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  void onStart() async {
    try {
      final appId = builds.first.appId;
      final wId = builds.first.workflowId;
      final branch = builds.first.branch;
      final result = await client.startBuild(appId, wId, branch);
      if (result.wasSuccessful) {
        print('Success!');
        onFetch();
      } else {
        print('Something went wrong: ${result.error}');
      }
    } catch (e) {
      print(e);
    }
  }

  void onCancel() async {
    try {
      final buildId = builds.first.id;
      final result = await client.cancelBuild(buildId);
      if (result.wasSuccessful) {
        print('Success!');
        onFetch();
      } else {
        print('Something went wrong: ${result.error}');
      }
    } catch (e) {
      print(e);
    }
  }

  void onFetch() async {
    try {
      final result = await client.getBuilds();
      if (result.wasSuccessful) {
        print('Success! Fetched ${result.data.applications.length}'
            ' apps and ${result.data.builds.length} builds');
        builds.clear();
        builds.addAll(result.data.builds);
        setState(() {});
      } else {
        print('Something went wrong: ${result.error}');
      }
    } catch (e) {
      print(e);
    }
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  codemagic_manager: ^0.2.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:codemagic_manager/codemagic_manager.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
6
Health:
Code health derived from static analysis. [more]
81
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
45
Learn more about scoring.

We analyzed this package on Jul 11, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14

Analysis suggestions

Package not compatible with SDK dart

Because:

  • codemagic_manager that is a package requiring null.

Health suggestions

Fix lib/src/model/application.g.dart. (-1 points)

Analysis of lib/src/model/application.g.dart reported 2 hints:

line 9 col 16: Name non-constant identifiers using lowerCamelCase.

line 42 col 22: Name non-constant identifiers using lowerCamelCase.

Fix lib/src/model/artefact.g.dart. (-1 points)

Analysis of lib/src/model/artefact.g.dart reported 2 hints:

line 9 col 13: Name non-constant identifiers using lowerCamelCase.

line 20 col 22: Name non-constant identifiers using lowerCamelCase.

Fix lib/src/model/build.g.dart. (-1 points)

Analysis of lib/src/model/build.g.dart reported 2 hints:

line 9 col 10: Name non-constant identifiers using lowerCamelCase.

line 53 col 22: Name non-constant identifiers using lowerCamelCase.

Fix additional 18 files with analysis or formatting issues. (-18 points)

Additional issues in the following files:

  • lib/src/model/build_action.g.dart (2 hints)
  • lib/src/model/build_response.g.dart (2 hints)
  • lib/src/model/build_settings.g.dart (2 hints)
  • lib/src/model/builds.g.dart (2 hints)
  • lib/src/model/cancel_build_response.g.dart (2 hints)
  • lib/src/model/code_signing.g.dart (2 hints)
  • lib/src/model/code_signing_android.g.dart (2 hints)
  • lib/src/model/code_signing_ios.g.dart (2 hints)
  • lib/src/model/code_signing_keystore.g.dart (2 hints)
  • lib/src/model/commit.g.dart (2 hints)
  • lib/src/model/config.g.dart (2 hints)
  • lib/src/model/owner.g.dart (2 hints)
  • lib/src/model/publishers.g.dart (2 hints)
  • lib/src/model/publishers_appstore_connect.g.dart (2 hints)
  • lib/src/model/publishers_email.g.dart (2 hints)
  • lib/src/model/publishers_github_releases.g.dart (2 hints)
  • lib/src/model/repository.g.dart (2 hints)
  • lib/src/model/workflow.g.dart (2 hints)

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (freezed_annotation).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
dio ^3.0.9 3.0.9
freezed_annotation ^0.7.1 0.7.1 0.11.0
meta ^1.1.8 1.2.2 1.3.0-nullsafety
Transitive dependencies
charcode 1.1.3
collection 1.14.13 1.15.0-nullsafety
http_parser 3.1.4
json_annotation 3.0.1
path 1.7.0
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.2.0 1.3.0-nullsafety
Dev dependencies
build_runner ^1.10.0
flutter_test
freezed ^0.10.9
json_serializable ^3.3.0