mydnic/changelog-commit-for-laravel

根据您的提交描述,自动在Laravel应用程序内生成变更日志

v0.1.0 2024-09-18 10:47 UTC

This package is auto-updated.

Last update: 2024-09-18 10:47:27 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

根据您的提交描述,自动在Laravel应用程序内为您的用户生成变更日志。

简介

在构建Web项目时,让用户知道每次发布中发生了什么变化,甚至在错误修复后,这是很重要的。您可能通过博客文章或社交媒体来做这件事,但仍然是一个手动过程。

此包将根据您的提交描述自动生成变更日志。它将从您的仓库中获取提交历史,并将提交描述中的消息存储在数据库表中。

然后您可以在应用程序中显示变更日志,甚至可以通过电子邮件将其发送给您的用户。

安装

您可以通过composer安装此包

composer require mydnic/changelog-commit-for-laravel

您可以使用以下命令发布和运行迁移

php artisan vendor:publish --tag="changelog-commit-for-laravel-migrations"
php artisan migrate

您可以使用以下命令发布配置文件

php artisan vendor:publish --tag="changelog-commit-for-laravel-config"

这是发布配置文件的内容

return [
    /**
     * The name of the table to store the changelog in.
     */
    'table_name' => 'changelogs',

    /**
     * The GitHub access token to use to fetch the commit history.
     */
    'github_access_token' => env('GITHUB_ACCESS_TOKEN'),

    /**
     * The GitHub repositories to fetch the commit history from.
     */
    'github_repositories' => [
        'mydnic/changelog-commit-for-laravel', // change me
        // other repositories if you want to fetch the commit history from multiple repositories
    ],
];

使用方法

在项目上安装包后,您应该在部署过程中添加changelod:fetch命令。

现在,每次部署应用程序时,变更日志将根据最新的提交消息进行更新。

编写您的提交消息

以下是一个提交消息的示例

fix: issue with authentication

> You can now login without any issue
> Enjoy!

如你所见,提交消息由多行组成。第一行是您的常规提交消息。其他行可以用来添加有关提交的更多详细信息。

但只有以>开头的其他行才会用于生成变更日志。

生成变更日志

在您推送提交后,您可以运行以下命令来获取提交历史。或者,您可以将其添加到部署流程中,以便您不必手动运行它。

php artisan changelog:fetch

这将从您的仓库中获取提交历史,并将提交描述中的消息(所有以>开头的行)存储在数据库表中。

显示变更日志

然后您可以在应用程序中显示变更日志,甚至可以通过电子邮件将其发送给您的用户。

以下是如何在您的应用程序中显示变更日志的示例

使用Changelog模型在您的应用程序中获取变更日志条目。

use Mydnic\ChangelogCommitForLaravel\Models\Changelog;

$changelogs = Changelog::latest()->paginate(50);

return view('changelog', compact('changelogs'));
// or return JSON response
return response()->json($changelogs);

前端示例

如果您有更多示例,请提交!

VueJS组件

<template>
    <div>
        <div
            v-for="date in Object.keys(groupedChangelog)"
            :key="date"
        >
            <h2 class="text-lg font-semibold text-gray-800 mt-5 mb-1 capitalize">
                {{ $filters.format(date, 'dddd DD MMM YYYY') }}
            </h2>
            <ul class="list-disc pl-4 text-gray-600 space-y-1">
                <li
                    v-for="item in groupedChangelog[date]"
                    :key="item.message"
                    class="text-sm"
                >
                    {{ item.message }}
                </li>
            </ul>
        </div>

        <div
            v-if="pagination.last_page > pagination.current_page"
            class="text-center mt-10"
        >
            <button
                class="btn btn-sm"
                :class="{ loading: isLoading }"
                :disabled="isLoading"
                @click="loadMore"
            >
                Load more...
            </button>
        </div>
    </div>
</template>

<script>
import { defineComponent } from 'vue'

export default defineComponent({
    data () {
        return {
            changelog: [],
            pagination: {}
        }
    },

    computed: {
        groupedChangelog () {
            return this.changelog.reduce((acc, item) => {
                const key = item.date
                if (!acc[key]) {
                    acc[key] = []
                }
                acc[key].push(item)
                return acc
            }, {})
        }
    },

    created () {
        this.getChangelog()
    },

    methods: {
        getChangelog (page = 1) {
            fetch('https://your-app.example/api/changelog?page=' + page)
                .then(response => response.json())
                .then((data) => {
                    this.changelog = [...this.changelog, ...data.data]
                    this.pagination = {
                        current_page: data.current_page,
                        last_page: data.last_page
                    }
                })
        },

        loadMore () {
            this.getChangelog(this.pagination.current_page + 1)
        }
    }
})
</script>

测试

composer test

变更日志

有关最近更改的更多信息,请参阅CHANGELOG

贡献

有关详细信息,请参阅CONTRIBUTING

安全漏洞

有关如何报告安全漏洞的详细信息,请参阅我们的安全策略

鸣谢

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件