-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(vscode): Use openvsx Signed-off-by: Ce Gao <cegao@tensorchord.ai> * fix: Check cache first Signed-off-by: Ce Gao <cegao@tensorchord.ai> * fix: Remove version in README Signed-off-by: Ce Gao <cegao@tensorchord.ai>
- Loading branch information
Showing
6 changed files
with
178 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package vscode | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/cockroachdb/errors" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func GetLatestVersionURL(p Plugin) (string, error) { | ||
// Auto-detect the version. | ||
// Refer to https://github.com/tensorchord/envd/issues/161#issuecomment-1129475975 | ||
latestURL := fmt.Sprintf(vendorOpenVSXTemplate, p.Publisher, p.Extension) | ||
resp, err := http.Get(latestURL) | ||
if err != nil { | ||
return "", errors.Wrap(err, "failed to get latest version") | ||
} | ||
defer resp.Body.Close() | ||
if resp.StatusCode != http.StatusOK { | ||
return "", errors.Errorf("failed to get latest version: %s", resp.Status) | ||
} | ||
jsonResp := make(map[string]interface{}) | ||
if err := json.NewDecoder(resp.Body).Decode(&jsonResp); err != nil { | ||
return "", errors.Wrap(err, "failed to decode response") | ||
} | ||
if jsonResp["files"] == nil { | ||
return "", errors.New("failed to get latest version: no files") | ||
} | ||
files := jsonResp["files"].(map[string]interface{}) | ||
if files["download"] == nil { | ||
return "", errors.New("failed to get latest version: no download url") | ||
} | ||
return files["download"].(string), nil | ||
} | ||
|
||
func ParsePlugin(p string) (*Plugin, error) { | ||
indexPublisher := strings.Index(p, ".") | ||
if indexPublisher == -1 { | ||
return nil, errors.New("invalid publisher") | ||
} | ||
publisher := p[:indexPublisher] | ||
|
||
indexExtension := strings.LastIndex(p[indexPublisher:], "-") | ||
if indexExtension == -1 { | ||
extension := p[indexPublisher+1:] | ||
logrus.WithFields(logrus.Fields{ | ||
"publisher": publisher, | ||
"extension": extension, | ||
}).Debug("vscode plugin is parsed without version") | ||
return &Plugin{ | ||
Publisher: publisher, | ||
Extension: extension, | ||
}, nil | ||
} | ||
|
||
indexExtension = indexPublisher + indexExtension | ||
extension := p[indexPublisher+1 : indexExtension] | ||
version := p[indexExtension+1:] | ||
if _, err := strconv.Atoi(version[0:1]); err != nil { | ||
extension := p[indexPublisher+1:] | ||
logrus.WithFields(logrus.Fields{ | ||
"publisher": publisher, | ||
"extension": extension, | ||
}).Debug("vscode plugin is parsed without version") | ||
return &Plugin{ | ||
Publisher: publisher, | ||
Extension: extension, | ||
}, nil | ||
} | ||
logrus.WithFields(logrus.Fields{ | ||
"publisher": publisher, | ||
"extension": extension, | ||
"version": version, | ||
}).Debug("vscode plugin is parsed") | ||
return &Plugin{ | ||
Publisher: publisher, | ||
Extension: extension, | ||
Version: &version, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters