masamune_model_github 3.6.3
masamune_model_github: ^3.6.3 copied to clipboard
Masamune plugin package that includes a model adapter to retrieve data from Github.
Masamune Model GitHub
[GitHub] | [YouTube] | [Packages] | [X] | [LinkedIn] | [mathru.net]
Masamune Model GitHub #
Usage #
Installation #
- Add the package to your project.
flutter pub add masamune_model_github
Setup #
- Create a GitHub API token and configure the adapter. The token should have the scopes required for the data you plan to access or mutate.
// lib/main.dart
import 'package:masamune_model_github/masamune_model_github.dart';
final githubAdapter = GithubModelAdapter(
onRetrieveToken: () async {
// Return your GitHub personal access token
// Store securely using environment variables or secret storage
return String.fromEnvironment("GITHUB_TOKEN");
},
);
final masamuneAdapters = <MasamuneAdapter>[
GithubModelMasamuneAdapter(
modelAdapter: githubAdapter,
appRef: appRef,
),
];
void main() {
runMasamuneApp(
appRef: appRef,
modelAdapter: githubAdapter,
masamuneAdapters: masamuneAdapters,
(appRef, _) => MasamuneApp(
appRef: appRef,
home: HomePage(),
),
);
}
Available Models #
The package provides pre-built models for GitHub API entities:
GithubRepositoryModel- RepositoriesGithubIssueModel- IssuesGithubPullRequestModel- Pull requestsGithubUserModel- UsersGithubOrganizationModel- OrganizationsGithubCommitModel- CommitsGithubBranchModel- BranchesGithubContentModel- Repository contentsGithubLabelModel- LabelsGithubMilestoneModel- MilestonesGithubProjectModel- Projects
Load GitHub Data #
- Load GitHub resources using the generated models:
class RepositoriesPage extends PageScopedWidget {
@override
Widget build(BuildContext context, PageRef ref) {
// Load repositories for an organization
final repos = ref.app.model(
GithubRepositoryModel.collection(organizationId: "flutter"),
)..load();
return ListView.builder(
itemCount: repos.length,
itemBuilder: (context, index) {
final repo = repos[index].value;
return ListTile(
title: Text(repo?.name ?? ''),
subtitle: Text(repo?.description ?? ''),
trailing: Text('⭐ ${repo?.stargazersCount ?? 0}'),
);
},
);
}
}
Load Issues and Pull Requests #
// Load issues for a repository
final issues = ref.app.model(
GithubIssueModel.collection(
organizationId: "flutter",
repositoryId: "flutter",
),
)..load();
// Load pull requests
final pullRequests = ref.app.model(
GithubPullRequestModel.collection(
organizationId: "flutter",
repositoryId: "flutter",
),
)..load();
Create/Update GitHub Resources #
// Create a new issue
final issueCollection = ref.app.model(
GithubIssueModel.collection(
organizationId: "myorg",
repositoryId: "myrepo",
),
);
final newIssue = issueCollection.create();
await newIssue.save(
GithubIssueModel(
title: 'Bug Report',
body: 'Description of the bug...',
labels: ['bug', 'high-priority'],
),
);
GitHub Token Setup #
Create a Personal Access Token at GitHub Settings → Developer settings → Personal access tokens.
Required scopes depend on your use case:
repo- Full control of private repositoriespublic_repo- Access public repositoriesread:org- Read org and team membershipuser- Read user profile data
Store the token securely:
# Set as environment variable
export GITHUB_TOKEN="ghp_your_token_here"
# Or use --dart-define
flutter run --dart-define=GITHUB_TOKEN=ghp_your_token_here
GitHub Sponsors #
Sponsors are always welcome. Thank you for your support!