Skip to content

Commit

Permalink
feat: Push changes back onto branch (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
thelukewalton committed Jun 26, 2024
1 parent 7057abf commit de3a43f
Show file tree
Hide file tree
Showing 12 changed files with 122 additions and 287 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ jobs:
git config --global user.name "github-actions"
git config --global user.email "[email protected]"
git add -A
git commit -m '[automated commit] lint format and import sort'
git commit -m 'ci(automated commit): lint format and import sort'
git push
27 changes: 24 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
# flutter-code-quality

### Making changes
An action that runs on PRs to format and test Flutter repos.

Use ncc to output, not tsc or others.
`ncc build src/main.ts`
### Usage

```yml
name: Pull Request

on:
pull_request:

jobs:
code-quality:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
repository: ${{github.event.pull_request.head.repo.full_name}}
ref: ${{ github.head_ref }}
- uses: subosito/flutter-action@v2
with:
cache: true
- uses: ZebraDevs/flutter-code-quality@main
with:
token: ${{secrets.GITHUB_TOKEN}}
```
265 changes: 0 additions & 265 deletions build/build.js

This file was deleted.

52 changes: 49 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30695,6 +30695,53 @@ const getOldCoverage = () => {
exports.getOldCoverage = getOldCoverage;


/***/ }),

/***/ 7523:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {

"use strict";

Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.push = void 0;
const core_1 = __nccwpck_require__(2614);
const exec_1 = __nccwpck_require__(2259);
const child_process_1 = __nccwpck_require__(2081);
const push = async () => {
(0, core_1.startGroup)("Check for changes");
let stdout = "";
try {
await (0, exec_1.exec)("git status --porcelain", [], {
listeners: { stdout: (data) => (stdout += data.toString()) },
});
}
catch (e) {
console.error("Unable to check if there are changes", e);
}
(0, core_1.endGroup)();
/// If `stdout` is empty, there are no changes
if (stdout != "") {
try {
(0, core_1.startGroup)("Push changes");
await (0, exec_1.exec)('git config --global user.name "github-actions"');
await (0, exec_1.exec)('git config --global user.email "[email protected]"');
await (0, exec_1.exec)("git add -A");
(0, child_process_1.execSync)(`git commit -m 'chore(automated): Lint commit and format' `);
await (0, exec_1.exec)("git push -f");
console.log("Changes pushed onto branch");
}
catch (e) {
console.error("Unable to push changes", e);
(0, core_1.setFailed)("Unable to push changes to branch");
}
finally {
(0, core_1.endGroup)();
}
}
};
exports.push = push;


/***/ }),

/***/ 7046:
Expand Down Expand Up @@ -33096,10 +33143,8 @@ const github_1 = __nccwpck_require__(8686);
const comment_1 = __nccwpck_require__(9498);
const setup_1 = __nccwpck_require__(7046);
const behind_1 = __nccwpck_require__(8058);
const push_1 = __nccwpck_require__(7523);
const run = async () => {
// const comment = `Test comment, ${Date.now().toLocaleString("en_GB")}
// <sub>Created with <a href='https://github.com/ZebraDevs/flutter-code-quality'>Flutter code quality action</a></sub>
// }`;
const token = process.env.GITHUB_TOKEN || (0, core_1.getInput)("token");
const octokit = (0, github_1.getOctokit)(token);
const behindByStr = await (0, behind_1.checkBranchStatus)(octokit, github_1.context);
Expand All @@ -33110,6 +33155,7 @@ const run = async () => {
const coverageStr = await (0, coverage_1.getCoverage)(oldCoverage);
const comment = (0, comment_1.createComment)(analyzeStr, testStr, coverageStr, behindByStr);
(0, comment_1.postComment)(octokit, comment, github_1.context);
await (0, push_1.push)();
};
run();

Expand Down
7 changes: 6 additions & 1 deletion src/analyze.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { exec } from "@actions/exec";

import { endGroup, startGroup } from "@actions/core";
import { analyzeDetails, analyzeErrTypes, stepResponse } from "./types";
import { stepResponse } from "./main";

export type analyzeDetails = { file: string; details: string };

export type analyzeErrTypes = "error" | "warning" | "info";

export const getAnalyze = async (): Promise<stepResponse> => {
startGroup("Analyzing code");
Expand Down
2 changes: 1 addition & 1 deletion src/behind.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { endGroup, startGroup } from "@actions/core";
import { Context } from "@actions/github/lib/context";
import { GitHub } from "@actions/github/lib/utils";
import { stepResponse } from "./types";
import { stepResponse } from "./main";

export const checkBranchStatus = async (
octokit: InstanceType<typeof GitHub>,
Expand Down
Loading

0 comments on commit de3a43f

Please sign in to comment.