<commit_before>// Copyright 2014 tsuru authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package cmd

import (
	"fmt"
	"net"
	"net/http"
	"os"
	"os/exec"
	"runtime"
)

func clientID() string {
	return os.Getenv("TSURU_AUTH_CLIENTID")
}

func open(url string) error {
	if runtime.GOOS == "linux" {
		return exec.Command("xdg-open", url).Start()
	}
	return exec.Command("open", url).Start()
}

func serve(url chan string, finish chan bool) {
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		defer func() {
			finish <- true
		}()
		fmt.Fprintf(w, "Test")
	})
	l, e := net.Listen("tcp", ":0")
	if e != nil {
		return
	}
	_, port, _ := net.SplitHostPort(l.Addr().String())
	url <- fmt.Sprintf("https://github.com/login/oauth/authorize?client_id=%s&redirect_uri=http://localhost:%s&scope=user:email", clientID(), port)
	server := &http.Server{}
	server.Serve(l)
}

func startServerAndOpenBrowser() {
	url := make(chan string)
	finish := make(chan bool)
	go func() {
		serve(url, finish)
	}()
	open(<-url)
	<-finish
}

func oauthLogin(context *Context, client *Client) error {
	startServerAndOpenBrowser()
	return nil
}
<commit_msg>cmd/oauth: support for configurable port.<commit_after>// Copyright 2014 tsuru authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package cmd

import (
	"fmt"
	"net"
	"net/http"
	"os"
	"os/exec"
	"runtime"
)

func clientID() string {
	return os.Getenv("TSURU_AUTH_CLIENTID")
}

func port() string {
	p := os.Getenv("TSURU_AUTH_SERVER_PORT")
	if p == "" {
		return ":0"
	}
	return p
}

func open(url string) error {
	if runtime.GOOS == "linux" {
		return exec.Command("xdg-open", url).Start()
	}
	return exec.Command("open", url).Start()
}

func serve(url chan string, finish chan bool) {
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		defer func() {
			finish <- true
		}()
		fmt.Fprintf(w, "Test")
	})
	l, e := net.Listen("tcp", port())
	if e != nil {
		return
	}
	_, port, _ := net.SplitHostPort(l.Addr().String())
	url <- fmt.Sprintf("https://github.com/login/oauth/authorize?client_id=%s&redirect_uri=http://localhost:%s&scope=user:email", clientID(), port)
	server := &http.Server{}
	server.Serve(l)
}

func startServerAndOpenBrowser() {
	url := make(chan string)
	finish := make(chan bool)
	go func() {
		serve(url, finish)
	}()
	open(<-url)
	<-finish
}

func oauthLogin(context *Context, client *Client) error {
	startServerAndOpenBrowser()
	return nil
}

{'fraction_non_alphanumeric': 0.16749903956972723, 'fraction_numerical': 0.00384172109104879, 'mean_word_length': 4.095890410958904, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7605643', 'n_tokens_mistral': 988, 'n_tokens_neox': 952, 'n_words': 239}