[MM-53968] Includes mattermost-plugin-api into the mono repo (#24235)

Include https://github.com/mattermost/mattermost-plugin-api into the mono repo

Co-authored-by: Jesse Hallam <jesse.hallam@gmail.com>
Co-authored-by: Michael Kochell <mjkochell@gmail.com>
Co-authored-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com>
Co-authored-by: Alex Dovenmuehle <alex.dovenmuehle@mattermost.com>
Co-authored-by: Michael Kochell <6913320+mickmister@users.noreply.github.com>
Co-authored-by: Christopher Poile <cpoile@gmail.com>
Co-authored-by: İlker Göktuğ Öztürk <ilkergoktugozturk@gmail.com>
Co-authored-by: Shota Gvinepadze <wineson@gmail.com>
Co-authored-by: Ali Farooq <ali.farooq0@pm.me>
Co-authored-by: Maria A Nunez <maria.nunez@mattermost.com>
Co-authored-by: Daniel Espino García <larkox@gmail.com>
Co-authored-by: Christopher Speller <crspeller@gmail.com>
Co-authored-by: Alex Dovenmuehle <adovenmuehle@gmail.com>
Co-authored-by: Szymon Gibała <szymongib@gmail.com>
Co-authored-by: Lev <1187448+levb@users.noreply.github.com>
Co-authored-by: Jason Frerich <jason.frerich@mattermost.com>
Co-authored-by: Agniva De Sarker <agnivade@yahoo.co.in>
Co-authored-by: Artur M. Wolff <artur.m.wolff@gmail.com>
Co-authored-by: Madhav Hugar <16546715+madhavhugar@users.noreply.github.com>
Co-authored-by: Joe <security.joe@pm.me>
Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>
Co-authored-by: José Peso <trilopin@users.noreply.github.com>
Этот коммит содержится в:
Ben Schumacher
2023-08-21 09:50:30 +02:00
коммит произвёл GitHub
родитель bc11b29807
Коммит 3ee5432664
117 изменённых файлов: 14912 добавлений и 5 удалений

Просмотреть файл

@@ -0,0 +1,21 @@
package common
import (
"errors"
"time"
"github.com/mattermost/mattermost/server/public/pluginapi"
)
var ErrNotFound = errors.New("not found")
type KVStore interface {
Set(key string, value interface{}, options ...pluginapi.KVSetOption) (bool, error)
SetWithExpiry(key string, value interface{}, ttl time.Duration) error
CompareAndSet(key string, oldValue, value interface{}) (bool, error)
CompareAndDelete(key string, oldValue interface{}) (bool, error)
Get(key string, o interface{}) error
Delete(key string) error
DeleteAll() error
ListKeys(page, count int, options ...pluginapi.ListKeysOption) ([]string, error)
}

Просмотреть файл

@@ -0,0 +1,8 @@
package common
type LogAPI interface {
LogError(message string, keyValuePairs ...interface{})
LogWarn(message string, keyValuePairs ...interface{})
LogInfo(message string, keyValuePairs ...interface{})
LogDebug(message string, keyValuePairs ...interface{})
}

Просмотреть файл

@@ -0,0 +1,22 @@
// Copyright (c) 2019-present Mattermost, Inc. All Rights Reserved.
// See License for license information.
package common
import (
"encoding/json"
"fmt"
)
func JSON(ref interface{}) string {
bb, _ := json.MarshalIndent(ref, "", " ")
return string(bb)
}
func CodeBlock(in string) string {
return fmt.Sprintf("\n```\n%s\n```\n", in)
}
func JSONBlock(ref interface{}) string {
return fmt.Sprintf("\n```json\n%s\n```\n", JSON(ref))
}

Просмотреть файл

@@ -0,0 +1,24 @@
package common
import (
"encoding/json"
"net/http"
"github.com/mattermost/mattermost/server/public/model"
)
func SlackAttachmentError(w http.ResponseWriter, err error) {
response := model.PostActionIntegrationResponse{
EphemeralText: "Error:" + err.Error(),
}
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(response)
}
func DialogError(w http.ResponseWriter, err error) {
response := model.SubmitDialogResponse{
Error: err.Error(),
}
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(response)
}

Просмотреть файл

@@ -0,0 +1,28 @@
package common
import (
"net/url"
"strings"
"github.com/mattermost/mattermost/server/public/pluginapi"
)
// GetPluginURL returns a url like siteURL/plugins/pluginID based on the information from the client.
// If any error happens in the process, a empty string is returned.
func GetPluginURL(client *pluginapi.Client) string {
mattermostSiteURL := client.Configuration.GetConfig().ServiceSettings.SiteURL
if mattermostSiteURL == nil {
return ""
}
_, err := url.Parse(*mattermostSiteURL)
if err != nil {
return ""
}
manifest, err := client.System.GetManifest()
if err != nil {
return ""
}
pluginURLPath := "/plugins/" + manifest.Id
return strings.TrimRight(*mattermostSiteURL, "/") + pluginURLPath
}