#8 delete cobra, add micro-config-flag (#11)

Убрана кобра, доработаны методы создания, закрытия пулл реквестов.

Co-authored-by: Gorbunov Kirill Andreevich <kgorbunov@mtsbank.ru>
Reviewed-on: #11
Co-authored-by: Кирилл Горбунов <kirya_gorbunov_2015@mail.ru>
Co-committed-by: Кирилл Горбунов <kirya_gorbunov_2015@mail.ru>
This commit is contained in:
Кирилл Горбунов
2024-04-02 22:54:15 +03:00
parent f913c01fca
commit eb2a21a1b1
24 changed files with 1337 additions and 1749 deletions

View File

@@ -1507,10 +1507,10 @@ __webpack_require__.r(__webpack_exports__);
/* harmony import */ var _util_isFunction__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../util/isFunction */ 2971);
function throwError(errorOrErroractory, scheduler) {
const Erroractory = (0,_util_isFunction__WEBPACK_IMPORTED_MODULE_0__.isFunction)(errorOrErroractory) ? errorOrErroractory : () => errorOrErroractory;
function throwError(errorOrErrorFactory, scheduler) {
const errorFactory = (0,_util_isFunction__WEBPACK_IMPORTED_MODULE_0__.isFunction)(errorOrErrorFactory) ? errorOrErrorFactory : () => errorOrErrorFactory;
const init = subscriber => subscriber.error(Erroractory());
const init = subscriber => subscriber.error(errorFactory());
return new _Observable__WEBPACK_IMPORTED_MODULE_1__.Observable(scheduler ? subscriber => scheduler.schedule(init, 0, subscriber) : init);
}
@@ -2963,17 +2963,17 @@ __webpack_require__.r(__webpack_exports__);
function throwIfEmpty(Erroractory = defaultErroractory) {
function throwIfEmpty(errorFactory = defaultErrorFactory) {
return (0,_util_lift__WEBPACK_IMPORTED_MODULE_0__.operate)((source, subscriber) => {
let hasValue = false;
source.subscribe(new _OperatorSubscriber__WEBPACK_IMPORTED_MODULE_1__.OperatorSubscriber(subscriber, value => {
hasValue = true;
subscriber.next(value);
}, () => hasValue ? subscriber.complete() : subscriber.error(Erroractory())));
}, () => hasValue ? subscriber.complete() : subscriber.error(errorFactory())));
});
}
function defaultErroractory() {
function defaultErrorFactory() {
return new _util_EmptyError__WEBPACK_IMPORTED_MODULE_2__.EmptyError();
}
@@ -51956,7 +51956,7 @@ function ɵɵresolveBody(element) {
*/
const INTERPOLATION_DELIMITER = `<EFBFBD>`;
const INTERPOLATION_DELIMITER = `<60>`;
/**
* Unwrap a value which might be behind a closure (for forward declaration reasons).
*/
@@ -52069,7 +52069,7 @@ function getExpressionChangedErrorDetails(lView, bindingIndex, oldValue, newValu
} // metadata is not available for this expression, check if this expression is a part of the
// property interpolation by going from the current binding index left and look for a string that
// contains INTERPOLATION_DELIMITER, the layout in tView.data for this case will look like this:
// [..., 'id<EFBFBD>Prefix <EFBFBD> and <EFBFBD> suffix', null, null, null, ...]
// [..., 'id<69>Prefix <20> and <20> suffix', null, null, null, ...]
if (metadata === null) {
@@ -56810,7 +56810,7 @@ function executeViewQueryFn(flags, viewQueryFn, component) {
* `LView`). Metadata are represented as `INTERPOLATION_DELIMITER`-delimited string with the
* following format:
* - `propertyName` for bound properties;
* - `propertyName<EFBFBD>prefix<EFBFBD>interpolation_static_part1<EFBFBD>..interpolation_static_partN<EFBFBD>suffix` for
* - `propertyName<6D>prefix<69>interpolation_static_part1<74>..interpolation_static_partN<74>suffix` for
* interpolated properties.
*
* @param tData `TData` where meta-data will be saved;
@@ -64853,13 +64853,13 @@ class OpCodeParser {
*/
const BINDING_REGEXP = /<EFBFBD>(\d+):?\d*<EFBFBD>/gi;
const ICU_REGEXP = /({\s*<EFBFBD>\d+:?\d*<EFBFBD>\s*,\s*\S{6}\s*,[\s\S]*})/gi;
const NESTED_ICU = /<EFBFBD>(\d+)<EFBFBD>/;
const ICU_BLOCK_REGEXP = /^\s*(<EFBFBD>\d+:?\d*<EFBFBD>)\s*,\s*(select|plural)\s*,/;
const MARKER = `<EFBFBD>`;
const SUBTEMPLATE_REGEXP = /<EFBFBD>\/?\*(\d+:\d+)<EFBFBD>/gi;
const PH_REGEXP = /<EFBFBD>(\/?[#*]\d+):?\d*<EFBFBD>/gi;
const BINDING_REGEXP = /<2F>(\d+):?\d*<2A>/gi;
const ICU_REGEXP = /({\s*<2A>\d+:?\d*<2A>\s*,\s*\S{6}\s*,[\s\S]*})/gi;
const NESTED_ICU = /<2F>(\d+)<29>/;
const ICU_BLOCK_REGEXP = /^\s*(<28>\d+:?\d*<2A>)\s*,\s*(select|plural)\s*,/;
const MARKER = `<60>`;
const SUBTEMPLATE_REGEXP = /<2F>\/?\*(\d+:\d+)<29>/gi;
const PH_REGEXP = /<2F>(\/?[#*]\d+):?\d*<2A>/gi;
/**
* Angular Dart introduced &ngsp; as a placeholder for non-removable space, see:
* https://github.com/dart-lang/angular/blob/0bb611387d29d65b5af7f9d2515ab571fd3fbee4/_tests/test/compiler/preserve_whitespace_test.dart#L25-L32
@@ -64942,7 +64942,7 @@ function i18nStartFirstCreatePass(tView, parentTNodeIndex, lView, index, message
}
} else {
// Odd indexes are placeholders (elements and sub-templates)
// At this point value is something like: '/#1:2' (originally coming from '<EFBFBD>/#1:2<EFBFBD>')
// At this point value is something like: '/#1:2' (originally coming from '<27>/#1:2<>')
const isClosing = value.charCodeAt(0) === 47
/* CharCode.SLASH */
;
@@ -65298,7 +65298,7 @@ function icuStart(tView, lView, updateOpCodes, parentIdx, icuExpression, anchorI
// It is an nested ICU expression
const icuIndex = nestedIcus.push(value) - 1; // Replace nested ICU expression by a comment node
valueArr[j] = `<!--<EFBFBD>${icuIndex}<EFBFBD>-->`;
valueArr[j] = `<!--<2D>${icuIndex}<7D>-->`;
}
}
@@ -65597,11 +65597,11 @@ function addCreateAttribute(create, newIndex, attr) {
const ROOT_TEMPLATE_ID = 0;
const PP_MULTI_VALUE_PLACEHOLDERS_REGEXP = /\[(<EFBFBD>.+?<3F>?)\]/;
const PP_PLACEHOLDERS_REGEXP = /\[(<EFBFBD>.+?<3F>?)\]|(<EFBFBD>\/?\*\d+:\d+<EFBFBD>)/g;
const PP_MULTI_VALUE_PLACEHOLDERS_REGEXP = /\[(<28>.+?<3F>?)\]/;
const PP_PLACEHOLDERS_REGEXP = /\[(<28>.+?<3F>?)\]|(<28>\/?\*\d+:\d+<2B>)/g;
const PP_ICU_VARS_REGEXP = /({\s*)(VAR_(PLURAL|SELECT)(_\d+)?)(\s*,)/g;
const PP_ICU_PLACEHOLDERS_REGEXP = /{([A-Z0-9_]+)}/g;
const PP_ICUS_REGEXP = /<EFBFBD>I18N_EXP_(ICU(_\d+)?)<EFBFBD>/g;
const PP_ICUS_REGEXP = /<2F>I18N_EXP_(ICU(_\d+)?)<29>/g;
const PP_CLOSE_TEMPLATE_REGEXP = /\/\*/;
const PP_TEMPLATE_ID_REGEXP = /\d+\:(\d+)/;
/**
@@ -65611,10 +65611,10 @@ const PP_TEMPLATE_ID_REGEXP = /\d+\:(\d+)/;
* format (that might contain some markers that we need to replace) to the final
* form, consumable by i18nStart instruction. Post processing steps include:
*
* 1. Resolve all multi-value cases (like [<EFBFBD>*1:1<EFBFBD><EFBFBD>#2:1<EFBFBD>|<EFBFBD>#4:1<EFBFBD>|<EFBFBD>5<EFBFBD>])
* 1. Resolve all multi-value cases (like [<5B>*1:1<><31>#2:1<>|<7C>#4:1<>|<7C>5<EFBFBD>])
* 2. Replace all ICU vars (like "VAR_PLURAL")
* 3. Replace all placeholders used inside ICUs in a form of {PLACEHOLDER}
* 4. Replace all ICU references with corresponding values (like <EFBFBD>ICU_EXP_ICU_1<EFBFBD>)
* 4. Replace all ICU references with corresponding values (like <20>ICU_EXP_ICU_1<5F>)
* in case multiple ICUs have the same placeholder name
*
* @param message Raw translation string for post processing
@@ -65627,13 +65627,13 @@ const PP_TEMPLATE_ID_REGEXP = /\d+\:(\d+)/;
function i18nPostprocess(message, replacements = {}) {
/**
* Step 1: resolve all multi-value placeholders like [<EFBFBD>#5<EFBFBD>|<EFBFBD>*1:1<EFBFBD><EFBFBD>#2:1<EFBFBD>|<EFBFBD>#4:1<EFBFBD>]
* Step 1: resolve all multi-value placeholders like [<5B>#5<>|<7C>*1:1<><31>#2:1<>|<7C>#4:1<>]
*
* Note: due to the way we process nested templates (BFS), multi-value placeholders are typically
* grouped by templates, for example: [<EFBFBD>#5<EFBFBD>|<EFBFBD>#6<EFBFBD>|<EFBFBD>#1:1<EFBFBD>|<EFBFBD>#3:2<EFBFBD>] where <EFBFBD>#5<EFBFBD> and <EFBFBD>#6<EFBFBD> belong to root
* template, <EFBFBD>#1:1<EFBFBD> belong to nested template with index 1 and <EFBFBD>#1:2<EFBFBD> - nested template with index
* 3. However in real templates the order might be different: i.e. <EFBFBD>#1:1<EFBFBD> and/or <EFBFBD>#3:2<EFBFBD> may go in
* front of <EFBFBD>#6<EFBFBD>. The post processing step restores the right order by keeping track of the
* grouped by templates, for example: [<5B>#5<>|<7C>#6<>|<7C>#1:1<>|<7C>#3:2<>] where <20>#5<> and <20>#6<> belong to root
* template, <20>#1:1<> belong to nested template with index 1 and <20>#1:2<> - nested template with index
* 3. However in real templates the order might be different: i.e. <20>#1:1<> and/or <20>#3:2<> may go in
* front of <20>#6<>. The post processing step restores the right order by keeping track of the
* template id stack and looks for placeholders that belong to the currently active template.
*/
let result = message;
@@ -65704,7 +65704,7 @@ function i18nPostprocess(message, replacements = {}) {
return replacements.hasOwnProperty(key) ? replacements[key] : match;
});
/**
* Step 4: replace all ICU references with corresponding values (like <EFBFBD>ICU_EXP_ICU_1<EFBFBD>) in case
* Step 4: replace all ICU references with corresponding values (like <20>ICU_EXP_ICU_1<5F>) in case
* multiple ICUs have the same placeholder name
*/
@@ -65739,14 +65739,14 @@ function i18nPostprocess(message, replacements = {}) {
* contain placeholders which associate inner elements and sub-templates within the translation.
*
* The translation `message` placeholders are:
* - `<EFBFBD>{index}(:{block})<EFBFBD>`: *Binding Placeholder*: Marks a location where an expression will be
* - `<60>{index}(:{block})<29>`: *Binding Placeholder*: Marks a location where an expression will be
* interpolated into. The placeholder `index` points to the expression binding index. An optional
* `block` that matches the sub-template in which it was declared.
* - `<EFBFBD>#{index}(:{block})<EFBFBD>`/`<EFBFBD>/#{index}(:{block})<EFBFBD>`: *Element Placeholder*: Marks the beginning
* - `<60>#{index}(:{block})<29>`/`<60>/#{index}(:{block})<29>`: *Element Placeholder*: Marks the beginning
* and end of DOM element that were embedded in the original translation block. The placeholder
* `index` points to the element index in the template instructions set. An optional `block` that
* matches the sub-template in which it was declared.
* - `<EFBFBD>*{index}:{block}<EFBFBD>`/`<EFBFBD>/*{index}:{block}<EFBFBD>`: *Sub-template Placeholder*: Sub-templates must be
* - `<60>*{index}:{block}<7D>`/`<60>/*{index}:{block}<7D>`: *Sub-template Placeholder*: Sub-templates must be
* split up and translated separately in each angular template function. The `index` points to the
* `template` instruction index. A `block` that matches the sub-template in which it was declared.
*
@@ -65801,14 +65801,14 @@ function ɵɵi18nEnd() {
* contain placeholders which associate inner elements and sub-templates within the translation.
*
* The translation `message` placeholders are:
* - `<EFBFBD>{index}(:{block})<EFBFBD>`: *Binding Placeholder*: Marks a location where an expression will be
* - `<60>{index}(:{block})<29>`: *Binding Placeholder*: Marks a location where an expression will be
* interpolated into. The placeholder `index` points to the expression binding index. An optional
* `block` that matches the sub-template in which it was declared.
* - `<EFBFBD>#{index}(:{block})<EFBFBD>`/`<EFBFBD>/#{index}(:{block})<EFBFBD>`: *Element Placeholder*: Marks the beginning
* - `<60>#{index}(:{block})<29>`/`<60>/#{index}(:{block})<29>`: *Element Placeholder*: Marks the beginning
* and end of DOM element that were embedded in the original translation block. The placeholder
* `index` points to the element index in the template instructions set. An optional `block` that
* matches the sub-template in which it was declared.
* - `<EFBFBD>*{index}:{block}<EFBFBD>`/`<EFBFBD>/*{index}:{block}<EFBFBD>`: *Sub-template Placeholder*: Sub-templates must be
* - `<60>*{index}:{block}<7D>`/`<60>/*{index}:{block}<7D>`: *Sub-template Placeholder*: Sub-templates must be
* split up and translated separately in each angular template function. The `index` points to the
* `template` instruction index. A `block` that matches the sub-template in which it was declared.
*
@@ -65877,10 +65877,10 @@ function ɵɵi18nApply(index) {
* format (that might contain some markers that we need to replace) to the final
* form, consumable by i18nStart instruction. Post processing steps include:
*
* 1. Resolve all multi-value cases (like [<EFBFBD>*1:1<EFBFBD><EFBFBD>#2:1<EFBFBD>|<EFBFBD>#4:1<EFBFBD>|<EFBFBD>5<EFBFBD>])
* 1. Resolve all multi-value cases (like [<5B>*1:1<><31>#2:1<>|<7C>#4:1<>|<7C>5<EFBFBD>])
* 2. Replace all ICU vars (like "VAR_PLURAL")
* 3. Replace all placeholders used inside ICUs in a form of {PLACEHOLDER}
* 4. Replace all ICU references with corresponding values (like <EFBFBD>ICU_EXP_ICU_1<EFBFBD>)
* 4. Replace all ICU references with corresponding values (like <20>ICU_EXP_ICU_1<5F>)
* in case multiple ICUs have the same placeholder name
*
* @param message Raw translation string for post processing
@@ -67599,19 +67599,19 @@ class EventEmitter_ extends rxjs__WEBPACK_IMPORTED_MODULE_0__.Subject {
subscribe(observerOrNext, error, complete) {
let nextFn = observerOrNext;
let Errorn = error || (() => null);
let errorFn = error || (() => null);
let completeFn = complete;
if (observerOrNext && typeof observerOrNext === 'object') {
const observer = observerOrNext;
nextFn = observer.next?.bind(observer);
Errorn = observer.error?.bind(observer);
errorFn = observer.error?.bind(observer);
completeFn = observer.complete?.bind(observer);
}
if (this.__isAsync) {
Errorn = _wrapInTimeout(Errorn);
errorFn = _wrapInTimeout(errorFn);
if (nextFn) {
nextFn = _wrapInTimeout(nextFn);
@@ -67624,7 +67624,7 @@ class EventEmitter_ extends rxjs__WEBPACK_IMPORTED_MODULE_0__.Subject {
const sink = super.subscribe({
next: nextFn,
error: Errorn,
error: errorFn,
complete: completeFn
});

File diff suppressed because one or more lines are too long

View File

@@ -5,11 +5,13 @@ import (
"context"
"encoding/json"
"errors"
"flag"
"fmt"
"io"
"net/http"
"os"
"os/exec"
"os/user"
"path/filepath"
"strings"
"text/template"
@@ -23,9 +25,11 @@ import (
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/object"
httpauth "github.com/go-git/go-git/v5/plumbing/transport/http"
"github.com/jdx/go-netrc"
yamlcodec "go.unistack.org/micro-codec-yaml/v4"
envconfig "go.unistack.org/micro-config-env/v4"
fileconfig "go.unistack.org/micro-config-file/v4"
microflag "go.unistack.org/micro-config-flag/v4"
"go.unistack.org/micro/v4/config"
"go.unistack.org/micro/v4/logger"
"go.unistack.org/micro/v4/logger/slog"
@@ -36,6 +40,24 @@ import (
// https://docs.github.com/ru/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
var initMsg = `
Pkgdashcli allows you to define a version update for a dependency and start
merge requests in version control systems.
Usage:
pkgdashcli --command {{command}} --path {{name of dep}}
Commands:
checkupdate | CheckUpdate collects a list of dependencies with the latest updates.
list | Returns a list of PR for this repository with update dependencies.
update --path {{name of one dep or empty for update all dep}} | Creates a PR with the specified dependency update in path or creates a PR with dependency updates for all modules if path is empty.
close --path {{name of one dep or empty for close all pr}} | Closes the PR for the specified dependency or closes all PRs with dependency updates if path is empty .
Flags:
--command | The command to execute
--path | The name of the module to create/close the PR, if empty, the command is executed for all modules.
`
var (
DefaultPullRequestTitle = `Bump {{.Name}} from {{.VersionOld}} to {{.VersionNew}}`
DefaultPullRequestBody = `Bumps {{.Name}} from {{.VersionOld}} to {{.VersionNew}}`
@@ -58,13 +80,19 @@ var (
".github": "github",
".gitlab": "gitlab",
}
repoAPI = map[string]string{
".gitea": "git.unistack.org",
".gogs": "gogs",
".github": "github.com/unistack-org",
".gitlab": "gitlab.mtsbank.ru",
}
)
type Data struct {
Modules map[string]modules.Update
}
func pkgdashcli() {
func main() {
var err error
ctx, cancel := context.WithCancel(context.Background())
@@ -94,14 +122,18 @@ func pkgdashcli() {
for _, configDir := range configDirs {
for _, configFile := range configFiles {
logger.Info(ctx, fmt.Sprintf("path: %s", filepath.Join(configDir, configFile)))
path := filepath.Join(configDir, configFile)
if _, err = os.Stat(path); os.IsNotExist(err) {
continue
}
c := fileconfig.NewConfig(
config.AllowFail(false),
config.Struct(cfg),
options.Codec(yamlcodec.NewCodec()),
fileconfig.Path(".gitea/pkgdashcli.yaml"),
fileconfig.Path(path),
)
err = c.Init(options.Context(ctx))
err = c.Init()
if err != nil {
logger.Error(ctx, fmt.Sprintf("failed to init config: %v", err))
}
@@ -111,8 +143,6 @@ func pkgdashcli() {
}
}
logger.Info(ctx, fmt.Sprintf("Load config... %s", cfg.Source.Repository))
if cfg.PullRequestBody == "" {
cfg.PullRequestBody = DefaultPullRequestBody
}
@@ -121,6 +151,22 @@ func pkgdashcli() {
cfg.PullRequestTitle = DefaultPullRequestTitle
}
cliCfg := &configcli.Cli{}
c := microflag.NewConfig(config.Struct(cliCfg), microflag.FlagErrorHandling(flag.ContinueOnError))
if err = c.Init(); err != nil {
logger.Fatal(ctx, fmt.Sprintf("init cli cfg failed: %v", err))
}
if err = c.Load(ctx); err != nil {
logger.Fatal(ctx, fmt.Sprintf("load cli cfg failed: %v", err))
}
if cliCfg.Path == "" && cliCfg.Command == "" {
fmt.Print(initMsg)
return
}
path := "."
if len(os.Args) > 1 {
path = os.Args[1]
@@ -173,71 +219,138 @@ func pkgdashcli() {
modules.Updates(updateOptions)
/*var repoGit, tokenGit string // nameGit = gitea, repoGit = pkgdash, tokenGit = {xxx}, machine??
if cfg.Source != nil {
repoGit = cfg.Source.TypeGit
tokenGit = cfg.Source.Token
} else {
repoGit = getRepoMgmt()
if repoGit == "unknown" {
logger.Fatal(ctx, "pkgdash/main failed to get repo management")
}
if err = getRepoMgmt(ctx, cfg); err != nil { // Filling in empty config fields.
logger.Error(ctx, err.Error())
}
usr, err := user.Current()
if err != nil {
logger.Error(ctx, "pkgdash/main can t get info user: %s", err)
} else {
n, err := netrc.Parse(filepath.Join(usr.HomeDir, ".netrc"))
if err != nil {
logger.Error(ctx, "pkgdash/main can t parse .netrc: %s", err)
}
tokenGit = n.Machine(repoGit).Get("password")
}
switch repoGit {
case "gitea":
for _, branch := range cfg.Branches {
err = giteaPullRequest(ctx, cfg, branch, mvs)
}
}*/
logger.Info(ctx, fmt.Sprintf("cfg: %v", cfg))
gitSource := source.NewSourceControl(*cfg)
for _, branch := range cfg.Branches {
for pathMod, mod := range mvs {
logger.Debug(ctx, fmt.Sprintf("Start update %s from %s to %s", pathMod, mod.Module.Version, mod.Version))
err = gitSource.RequestOpen(ctx, branch, pathMod, mod)
if err != nil {
logger.Error(ctx, fmt.Sprintf("failed to create pr: %v", err))
}
logger.Debug(ctx, fmt.Sprintf("Update successful for %s", pathMod))
}
}
// err = gitSource.RequestClose(ctx, "master", "modernc.org/ccgo/v4")
Execute(ctx, gitSource, mvs, *cliCfg, *cfg)
logger.Info(ctx, "Pkgdash successfully updated dependencies")
}
func getRepoMgmt() string {
func Execute(ctx context.Context, gitSource source.SourceControl, mvs map[string]modules.Update, cliCfg configcli.Cli, cfg configcli.Config) {
var mod modules.Update
var ok bool
var path string
prList := make(map[string]map[string]string)
switch cliCfg.Command {
case "checkupdate":
js, err := json.Marshal(mvs)
fmt.Println(fmt.Sprintf(`Modules get update: %s, %s`, js, err))
case "update":
if cliCfg.Path != "" { // update one dep
path = cliCfg.Path
if mod, ok = mvs[path]; !ok {
logger.Fatal(ctx, fmt.Sprintf("For %s update not exist", path))
}
logger.Debugf(ctx, fmt.Sprintf("Start update %s from %s to %s", path, mod.Module.Version, mod.Version))
for _, branch := range cfg.Branches {
if err := gitSource.RequestOpen(ctx, branch, path, mod); err != nil {
logger.Fatal(ctx, fmt.Sprintf("failed to create pr: %v", err))
}
}
logger.Debugf(ctx, fmt.Sprintf("Update successful for %s", path))
return
}
for _, branch := range cfg.Branches { // update all dep
for path, mod = range mvs {
logger.Debugf(ctx, fmt.Sprintf("Start update %s from %s to %s", path, mod.Module.Version, mod.Version))
err := gitSource.RequestOpen(ctx, branch, path, mod)
if err != nil {
logger.Fatal(ctx, fmt.Sprintf("failed to create pr: %v", err))
}
logger.Debugf(ctx, fmt.Sprintf("Update successful for %s", path))
}
}
case "close":
if cliCfg.Path != "" { // close one dep
path = cliCfg.Path
logger.Debugf(ctx, fmt.Sprintf("Start close for %s", path))
for _, branch := range cfg.Branches {
if err := gitSource.RequestClose(ctx, branch, path); err != nil {
logger.Fatal(ctx, fmt.Sprintf("failed to close pr: %v", err))
}
}
logger.Debugf(ctx, fmt.Sprintf("Close successful for %s", path))
return
}
for _, branch := range cfg.Branches {
logger.Info(ctx, fmt.Sprintf("Start getting pr for %s", branch))
rMap, err := gitSource.RequestList(ctx, branch)
if err != nil {
logger.Fatal(ctx, fmt.Sprintf("Error with getting pr list for branch: %s", branch))
}
logger.Info(ctx, fmt.Sprintf("for %s:\n%s", branch, rMap))
logger.Info(ctx, fmt.Sprintf("Start close pr for base branch %s", branch))
for path, _ = range rMap {
logger.Debugf(ctx, fmt.Sprintf("Start close for %s", path))
if err = gitSource.RequestClose(ctx, branch, path); err != nil {
logger.Fatal(ctx, fmt.Sprintf("failed to close pr: %v", err))
}
logger.Debugf(ctx, fmt.Sprintf("Close successful for %s", path))
}
}
case "list":
for _, branch := range cfg.Branches {
rMap, err := gitSource.RequestList(ctx, branch)
if err != nil {
logger.Fatal(ctx, fmt.Sprintf("RequestList: error %s", err))
}
prList[branch] = rMap
}
js, err := json.Marshal(prList)
if err != nil {
logger.Error(ctx, fmt.Sprintf("error: %s", err))
}
fmt.Println(fmt.Sprintf("for %s:\n%s", cfg.Source.Repository, js))
default:
fmt.Print(initMsg)
}
}
func getRepoMgmt(ctx context.Context, cfg *configcli.Config) error {
wd, err := os.Getwd()
if err != nil {
return "unknown"
return err
}
p := filepath.Clean(wd)
for {
for _, configDir := range configDirs {
_, err := os.Stat(filepath.Join(p, configDir))
if name, ok := repoMgmt[configDir]; ok && err == nil {
return name
}
for _, configDir := range configDirs {
_, err := os.Stat(filepath.Join(p, configDir))
if name, ok := repoMgmt[configDir]; ok && cfg.Source.TypeGit == "" && err == nil {
cfg.Source.TypeGit = name
}
if p == "/" {
return "unknown"
if api, ok := repoAPI[configDir]; ok && cfg.Source.APIURL == "" && err == nil {
cfg.Source.APIURL = api
}
p = filepath.Clean(filepath.Join(p, ".."))
}
if p == "/" && cfg.Source.TypeGit == "" && cfg.Source.APIURL == "" {
return fmt.Errorf("unknown")
}
p = filepath.Clean(filepath.Join(p, ".."))
usr, err := user.Current()
if err != nil {
logger.Fatal(ctx, fmt.Sprintf("pkgdash/main can t get info about user: %s", err))
}
n, err := netrc.Parse(filepath.Join(usr.HomeDir, ".netrc"))
if err != nil {
logger.Error(ctx, "pkgdash/main can t parse .netrc: %s", err)
}
if cfg.Source.Owner == "" {
cfg.Source.Owner = n.Machine(cfg.Source.APIURL).Get("login")
}
if cfg.Source.Token == "" {
cfg.Source.Token = n.Machine(cfg.Source.APIURL).Get("password")
}
return nil
}
func giteaPullRequest(ctx context.Context, cfg *configcli.Config, branch string, mods map[string]modules.Update) error {

View File

@@ -1,7 +0,0 @@
package main
import "git.unistack.org/unistack-org/pkgdash/internal/cli"
func main() {
cli.Execute()
}