-
-
Notifications
You must be signed in to change notification settings - Fork 11
50 lines (43 loc) · 1.97 KB
/
add_repository.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
name: Add Repository
on:
workflow_dispatch:
inputs:
repository_url:
description: 'Repository URL or shorthand (e.g., libAudioFlux/audioFlux)'
required: true
jobs:
add_repository:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '16' # Imposta la versione di Node.js su 16
- name: Install Dependencies
run: |
npm install github-api
- name: Add Repository if Not Exists
run: |
const fs = require('fs');
const github = require('@actions/github');
const repositoryUrl = process.env.INPUT_REPOSITORY_URL.trim();
const owner = github.context.repo.owner;
const repo = github.context.repo.repo;
const filePath = '.github/SUBMITTED.md';
const contentToAppend = `|[${repo}](${repositoryUrl})||[![](https://img.shields.io/github/languages/top/${owner}/${repo}?color=pink&style=flat-square)](https://github.com/${owner}/${repo}/graphs/contributors)|[![](https://flat.badgen.net/github/license/${owner}/${repo}?label=)](https://github.com/${owner}/${repo}/blob/master/LICENSE)|[![](https://flat.badgen.net/github/last-commit/${owner}/${repo}?label=)](https://github.com/${owner}/${repo}/graphs/code-frequency)|\n`;
try {
const existingContent = fs.readFileSync(filePath, 'utf8');
if (!existingContent.includes(repositoryUrl)) {
fs.appendFileSync(filePath, contentToAppend);
console.log(`Repository ${repositoryUrl} added to ${filePath}`);
} else {
console.log(`Repository ${repositoryUrl} already exists in ${filePath}`);
}
} catch (error) {
console.error('Error:', error);
process.exit(1);
}
env:
INPUT_REPOSITORY_URL: ${{ github.event.inputs.repository_url }}