Skip to content

Commit

Permalink
feat: Remove NO JIRA badge when no JIRA instance has been set, chore:…
Browse files Browse the repository at this point in the history
… Reformat code, feat: Add workflows
  • Loading branch information
toohard2explain committed Jun 12, 2024
1 parent 34c09e3 commit 329f79a
Show file tree
Hide file tree
Showing 16 changed files with 463 additions and 343 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "npm" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "daily"
File renamed without changes.
27 changes: 27 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Format

on:
push:
branches:
- "**"
-
jobs:
formatting:
name: Code Formatting
runs-on: ubuntu-22.04
timeout-minutes: 10
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Setup Node.js 20
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm

- name: Install Dependencies
run: npm install

- name: Run Tests
run: npm run test:format
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# GH App Labels and Badges

## Overview

Automatically label your Pull Requests based on various criteria to streamline your workflow and make it easier to manage and track changes. You can configure the labels, sizing criteria, and other behaviors to suit your project's needs.

## Sizing Labels

| Label | Description |
|-----------------|-----------------------------------------------------|
| --------------- | --------------------------------------------------- |
| **PR:size/XS** | Added when additions or deletions are less than 10. |
| **PR:size/S** | Added when additions or deletions are 10-30. |
| **PR:size/M** | Added when additions or deletions are 30-100. |
Expand All @@ -17,7 +18,7 @@ Automatically label your Pull Requests based on various criteria to streamline y
## Other Labels

| Label | Description |
|--------------------------|---------------------------------------------------------------------------|
| ------------------------ | ------------------------------------------------------------------------- |
| **release** | Applied when the Pull Request is raised to the main branch. |
| **feature** | Applied when the branch name starts with "feat." |
| **bug** | Applied when the branch name starts with "fix" or "bug." |
Expand All @@ -28,10 +29,13 @@ Automatically label your Pull Requests based on various criteria to streamline y
| **PR:APPROVED** | Applied when a PR is approved. |

## Change Notes

Whenever a PR is raised or updated, a comment with all the changes, including JIRA hyperlinks, is automatically added as release notes. You have the option to disable this feature via configuration.

## Configuration

### Default Configuration

To configure the behavior of the application, create a `.github/labels-and-badges.yml` file with the following YAML structure:

```yaml
Expand Down Expand Up @@ -79,10 +83,10 @@ If you have suggestions for how gh-app-labels-and-badges could be improved, or w

For more, check out the [Contributing Guide](CONTRIBUTING.md).


> A GitHub App built with [Probot](https://github.com/probot/probot)
# ROADMAP

- [ ] Setup CI/CD
- [ ] Setup Linters and git hooks
- [ ]
- [ ]
28 changes: 14 additions & 14 deletions app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ default_events:
# - issue_comment
- issues
- label
# - milestone
# - member
# - membership
# - org_block
# - organization
# - page_build
# - project
# - project_card
# - project_column
# - public
# - milestone
# - member
# - membership
# - org_block
# - organization
# - page_build
# - project
# - project_card
# - project_column
# - public
- pull_request
- pull_request_review
- pull_request_review_comment
# - push
# - release
# - repository
# - repository_import
# - push
# - release
# - repository
# - repository_import
- status
# - team
# - team_add
Expand Down
21 changes: 19 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"build": "tsc",
"start": "yarn build && probot run ./lib/index.js",
"start:prod": "probot run ./lib/index.js",
"test": "jest"
"test": "jest",
"format": "prettier --write .",
"test:format": "prettier --check ."
},
"dependencies": {
"probot": "^12.2.4"
Expand All @@ -25,6 +27,7 @@
"@types/node": "^18.0.0",
"jest": "^29.0.0",
"nock": "^13.0.5",
"prettier": "^3.3.2",
"smee-client": "^1.2.2",
"ts-jest": "^29.0.0",
"typescript": "^4.1.3"
Expand Down
64 changes: 32 additions & 32 deletions src/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
interface SizeLabelConfig {
lines: number;
lines: number;
}

interface ConfigFile {
jira_url: string;
pr_size_config: {
xs: SizeLabelConfig;
s: SizeLabelConfig;
m: SizeLabelConfig;
l: SizeLabelConfig;
xl: SizeLabelConfig;
xxl: SizeLabelConfig;
}
release_branch: string;
enable_change_notes: boolean;
jira_url: string;
pr_size_config: {
xs: SizeLabelConfig;
s: SizeLabelConfig;
m: SizeLabelConfig;
l: SizeLabelConfig;
xl: SizeLabelConfig;
xxl: SizeLabelConfig;
};
release_branch: string;
enable_change_notes: boolean;
}

export class Config {
readonly jiraUrl: string;
readonly xsSizeLines: number;
readonly sSizeLines: number;
readonly mSizeLines: number;
readonly lSizeLines: number;
readonly xlSizeLines: number;
readonly xxlSizeLines: number;
readonly releaseBranch: string;
readonly enableChangeNotes: boolean;
readonly jiraUrl: string;
readonly xsSizeLines: number;
readonly sSizeLines: number;
readonly mSizeLines: number;
readonly lSizeLines: number;
readonly xlSizeLines: number;
readonly xxlSizeLines: number;
readonly releaseBranch: string;
readonly enableChangeNotes: boolean;

constructor(configFile: ConfigFile) {
this.jiraUrl = configFile?.jira_url || '';
this.xsSizeLines = configFile?.pr_size_config?.xs?.lines || 10;
this.sSizeLines = configFile?.pr_size_config?.s?.lines || 30;
this.mSizeLines = configFile?.pr_size_config?.m?.lines || 100;
this.lSizeLines = configFile?.pr_size_config?.l?.lines || 500;
this.xlSizeLines = configFile?.pr_size_config?.xl?.lines || 1000;
this.xxlSizeLines = configFile?.pr_size_config?.xxl?.lines || 10000;
this.releaseBranch = configFile?.release_branch || 'main';
this.enableChangeNotes = configFile?.enable_change_notes || false;
}
constructor(configFile: ConfigFile) {
this.jiraUrl = configFile?.jira_url || "";
this.xsSizeLines = configFile?.pr_size_config?.xs?.lines || 10;
this.sSizeLines = configFile?.pr_size_config?.s?.lines || 30;
this.mSizeLines = configFile?.pr_size_config?.m?.lines || 100;
this.lSizeLines = configFile?.pr_size_config?.l?.lines || 500;
this.xlSizeLines = configFile?.pr_size_config?.xl?.lines || 1000;
this.xxlSizeLines = configFile?.pr_size_config?.xxl?.lines || 10000;
this.releaseBranch = configFile?.release_branch || "main";
this.enableChangeNotes = configFile?.enable_change_notes || false;
}
}
106 changes: 55 additions & 51 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,64 @@
import {Probot} from 'probot';
import { Probot } from "probot";
import assignPullRequestLabels from "./labels/pull-request-labels";
import assignReviewLabels from "./labels/review-labels";
import {createLabelsIfNotExists} from "./labels/label-helpers";
import {addChangeNotes} from "./summary";
import {Config} from "./config/config";
import { createLabelsIfNotExists } from "./labels/label-helpers";
import { addChangeNotes } from "./summary";
import { Config } from "./config/config";

const preHook = async (context: any): Promise<{
existingLabels: any;
config: Config;
const preHook = async (
context: any,
): Promise<{
existingLabels: any;
config: Config;
}> => {
await createLabelsIfNotExists(context);
const config = await context.config('labels-and-badges.yml');
return {
existingLabels: await context.octokit.issues.listLabelsOnIssue(context.issue()),
config: new Config(config)
}
}
await createLabelsIfNotExists(context);
const config = await context.config("labels.yml");
return {
existingLabels: await context.octokit.issues.listLabelsOnIssue(
context.issue(),
),
config: new Config(config),
};
};

const pullRequestHandler = async (context: any, skipChangeNotes: boolean) => {
const {existingLabels, config} = await preHook(context);
await assignPullRequestLabels(context, existingLabels, config);
if (config.enableChangeNotes && !skipChangeNotes) {
await addChangeNotes(context, config);
}
}
const { existingLabels, config } = await preHook(context);
await assignPullRequestLabels(context, existingLabels, config);
if (config.enableChangeNotes && !skipChangeNotes) {
await addChangeNotes(context, config);
}
};

export = (app: Probot) => {
app.on('pull_request.opened', async (context) => {
context.log.info('pull_request.opened')
await pullRequestHandler(context, false);
});

app.on('pull_request.edited', async (context) => {
context.log.info('pull_request.edited')
await pullRequestHandler(context, true);
});

app.on('pull_request.reopened', async (context) => {
context.log.info('pull_request.reopened')
await pullRequestHandler(context, true);
});

app.on('pull_request.synchronize', async (context) => {
context.log.info('pull_request.synchronize')
await pullRequestHandler(context, false);
});

app.on('pull_request_review.submitted', async (context) => {
context.log.info('pull_request_review.submitted')
const { existingLabels } = await preHook(context);
await assignReviewLabels(context, existingLabels);
});

// For more information on building apps:
// https://probot.github.io/docs/

// To get your app running against GitHub, see:
// https://probot.github.io/docs/development/
app.on("pull_request.opened", async (context) => {
context.log.info("pull_request.opened");
await pullRequestHandler(context, false);
});

app.on("pull_request.edited", async (context) => {
context.log.info("pull_request.edited");
await pullRequestHandler(context, true);
});

app.on("pull_request.reopened", async (context) => {
context.log.info("pull_request.reopened");
await pullRequestHandler(context, true);
});

app.on("pull_request.synchronize", async (context) => {
context.log.info("pull_request.synchronize");
await pullRequestHandler(context, false);
});

app.on("pull_request_review.submitted", async (context) => {
context.log.info("pull_request_review.submitted");
const { existingLabels } = await preHook(context);
await assignReviewLabels(context, existingLabels);
});

// For more information on building apps:
// https://probot.github.io/docs/

// To get your app running against GitHub, see:
// https://probot.github.io/docs/development/
};
4 changes: 2 additions & 2 deletions src/labels/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './review-labels';
export * from './pull-request-labels';
export * from "./review-labels";
export * from "./pull-request-labels";
Loading

0 comments on commit 329f79a

Please sign in to comment.