Skip to content

Instantly share code, notes, and snippets.

View mrueegg's full-sized avatar

Michael Rüegg mrueegg

View GitHub Profile
@mrueegg
mrueegg / atlassian-plugin.xml
Created March 9, 2017 17:14
Web item to resolve open tasks in a pull request in Stash
<web-item key="stash-close-open-tasks-button" weight="90"
section="stash.pull-request.toolbar.actions" application="stash">
<condition class="ch.mibex.crossproduct.stash.HasOpenTasksCondition" />
<label key="open.tasks.resolve.label"/>
<tooltip key="open.tasks.resolve.tooltip"/>
<styleClass>resolve-open-tasks</styleClass>
</web-item>
@mrueegg
mrueegg / pom.xml
Created March 9, 2017 17:14
Shipping the Scala library for 2.11 with the plug-in
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<properties>
@mrueegg
mrueegg / pom.xml
Created March 9, 2017 17:14
Maven compiler plug-in configuration to use Java 1.8
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target><!-- use 1.7 in your Stash module -->
</configuration>
</plugin>
@mrueegg
mrueegg / pom.xml
Created March 9, 2017 17:13
Maven modules necessary for a cross-product plug-in
<modules>
<module>api</module>
<module>stash</module>
<module>bitbucket</module>
<module>plugin</module>
</modules>
<packaging>pom</packaging>
@mrueegg
mrueegg / atlassian-plugin.xml
Created March 9, 2017 17:13
Usage of the Java Soy function adapter
<soy-function key="navuser-absolute-function" class="com.company.plugin.UserNavSoyFunctionAdapter"/>
@mrueegg
mrueegg / UserNavSoyFunctionAdapter.java
Created March 9, 2017 17:12
Java SOY function adapter for the Scala implementation
public class UserNavSoyFunctionAdapter implements SoyServerFunction<String>, SoyClientFunction {
private final UserNavSoyFunction adaptee;
public UserNavSoyFunctionAdapter(UserNavSoyFunction adaptee) {
this.adaptee = adaptee;
}
@Override
public JsExpression generate(JsExpression... jsExpressions) {
Seq<JsExpression> scalaExpressions = scala.collection.JavaConversions.asScalaBuffer(
@mrueegg
mrueegg / UserNavSoyFunction.scala
Created March 9, 2017 17:12
Server-side SOY function to render user information in Bitbucket Server
class UserNavSoyFunction(navBuilder: NavBuilder) extends SoyServerFunction[String] with SoyClientFunction {
override def getName: String = "my_nav_user_absolute"
override def validArgSizes(): JSet[Integer] = Set(1).asJava
override def apply(args: AnyRef*): String = args.toList match {
case (user: ApplicationUser) :: Nil => navBuilder.user(user).buildAbsolute()
case _ => ""
}
@mrueegg
mrueegg / oauth.py
Created March 9, 2017 17:11
Authenticate with OAuth and Python for an Atlassian application
headers = {
'Accept': 'application/json',
'Content-Type': 'application/json; charset=UTF-8'
}
r = oauth.get('http://localhost:6990/bamboo/rest/api/latest/project?expand=projects', headers=headers)
print json.loads(r.text)
@mrueegg
mrueegg / oauth.py
Created March 9, 2017 17:11
Create an OAuth access token with Python
# we do not have a real verifier but we need to specify one, so we just use a hardcoded value
access_token = oauth.fetch_access_token(access_token_url, verifier=u'unused')
@mrueegg
mrueegg / oauth.py
Created March 9, 2017 17:10
Create an OAuth request token with Python
from oauthlib.oauth1 import SIGNATURE_RSA
from requests_oauthlib import OAuth1Session
import json
import webbrowser
request_token_url = 'http://localhost:6990/bamboo/plugins/servlet/oauth/request-token'
oauth = OAuth1Session(your_consumer_key_from_above,
signature_type='auth_header',
signature_method=SIGNATURE_RSA,
rsa_key=your_RSA_key_from_above)
request_token = oauth.fetch_request_token(request_token_url)