Skip to content
This repository has been archived by the owner on Jan 17, 2024. It is now read-only.

Add a sample extension for the new repo service #109

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions repository-info-extension/context.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<html>
<head>
<title>Repository Information</title>
<script src="node_modules/vss-web-extension-sdk/lib/VSS.SDK.js"></script>
<style>
h2 {
font-weight: 400;
}

pre {
font-size: 14px;
line-height: 1.3em;
}

</style>
</head>

<body style="padding-left: 20px; padding-top: 20px; overflow-y: auto; background-color: #eee">

<h2>Repository Information</h2>
<pre id="context-display"></pre>

<script type="text/javascript">
VSS.init({
usePlatformScripts: true,
usePlatformStyles: true
});

VSS.require(["scripts/app"], function (app) {
app.execute();
});
</script>

<div id="repository-info-view">
<h3>ID</h2>
<p id="repository-id"></p>
<h3>Name</h2>
<p id="repository-name"></p>
<h3>URL</h2>
<p id="repository-url"></p>
</div>
</body>
</html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added repository-info-extension/images/hub-content.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 60 additions & 0 deletions repository-info-extension/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions repository-info-extension/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "repository-info-extension",
"version": "1.0.0",
"description": "Provides an example for accessing the currently selected repository from an extension.",
"repository": {
"type": "git",
"url": "https://github.com/Microsoft/vsts-extension-samples/tree/master/repository-info-extension"
},
"author": "Microsoft",
"dependencies": {
"vss-web-extension-sdk": "^5.140.0"
}
}
13 changes: 13 additions & 0 deletions repository-info-extension/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
This extension is an example of how to access information about the user's currently selected repository from an extension. Note: this information will only be accessible on pages that are within the "code" hub, including new pages that may be added by the extension (as in this example).

## Building

This extension is built using NodeJS with the [typescript](https://github.com/Microsoft/TypeScript) and [tfs-cli](https://github.com/Microsoft/tfs-cli) packages. Once those are installed, open a command prompt at the extension's root and run:

1. `npm install`
2. `tsc`
3. `tfx extension create`

## Screenshot

![hub](images/hub-content.PNG)
14 changes: 14 additions & 0 deletions repository-info-extension/scripts/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// <reference path='../node_modules/vss-web-extension-sdk/typings/tfs.d.ts' />

import TFS_VC_Services = require("TFS/VersionControl/Services");

export async function execute() {
const svc = await TFS_VC_Services.VersionControlRepositoryService.getService();
const repo = await svc.getCurrentGitRepository();
let idContainer = document.getElementById("repository-id");
let nameContainer = document.getElementById("repository-name");
let urlContainer = document.getElementById("repository-url");
idContainer.innerHTML = repo.id;
nameContainer.innerHTML = repo.name;
urlContainer.innerHTML = repo.url;
}
9 changes: 9 additions & 0 deletions repository-info-extension/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"module": "amd",
"sourceMap": false
},
"exclude": [
"node_modules"
]
}
68 changes: 68 additions & 0 deletions repository-info-extension/vss-extension.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"manifestVersion": 1,
"id": "repository-info-extension",
"version": "1.0.0",
"name": "Repository Information Sample",
"description": "Provides an example for accessing the currently selected repository from an extension.",
"publisher": "ms-samples",
"public": true,
"categories": [
cadewey marked this conversation as resolved.
Show resolved Hide resolved
"Developer samples",
"Code"
],
"links": {
"learn": {
"uri": "https://github.com/Microsoft/vso-extension-samples"
}
},
"icons": {
"default": "images/fabrikam-logo.png"
},
"targets": [
{
"id": "Microsoft.VisualStudio.Services"
}
],
"content": {
"details": {
"path": "readme.md"
}
},
"branding": {
"color": "rgb(190, 39, 3)",
"theme": "dark"
},
"files": [
{
"path": "scripts/app.js",
"addressable": true
},
{
"path": "images",
"addressable": true
},
{
"path": "context.html",
"addressable": true
},
{
"path": "node_modules/vss-web-extension-sdk/lib",
"addressable": true
}
],
"contributions": [
{
"id": "repository-info-hub",
"type": "ms.vss-web.hub",
"description": "Custom hub in the Code hub group that displays information about the currently active Git repository.",
"targets": [
"ms.vss-code-web.code-hub-group"
],
"properties": {
"name": "Repository Information",
"order": 100,
"uri": "context.html"
}
}
]
}